src/rl_addons/rl_accel/_rl_accel.c
author robin <robin@reportlab.com>
Fri, 23 Mar 2018 16:02:08 +0000
changeset 4389 61a7f0840d00
parent 4330 617ffa6bbdc8
child 4413 dec33c7e7922
permissions -rw-r--r--
more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2816
5554d8b5a2c2 _rl_accel.c: firm up license details
rgbecker
parents: 2712
diff changeset
     1
/*
4330
617ffa6bbdc8 changes for release 3.4.0
robin <robin@reportlab.com>
parents: 4267
diff changeset
     2
* Copyright ReportLab Europe Ltd. 2000-2017
2816
5554d8b5a2c2 _rl_accel.c: firm up license details
rgbecker
parents: 2712
diff changeset
     3
* licensed under the same terms as the ReportLab Toolkit
5554d8b5a2c2 _rl_accel.c: firm up license details
rgbecker
parents: 2712
diff changeset
     4
* see http://www.reportlab.co.uk/svn/public/reportlab/trunk/reportlab/license.txt
5554d8b5a2c2 _rl_accel.c: firm up license details
rgbecker
parents: 2712
diff changeset
     5
* for details.
5554d8b5a2c2 _rl_accel.c: firm up license details
rgbecker
parents: 2712
diff changeset
     6
* history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/lib/_rl_accel.c
5554d8b5a2c2 _rl_accel.c: firm up license details
rgbecker
parents: 2712
diff changeset
     7
*/
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
     8
#include "Python.h"
3727
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
     9
#if PY_MAJOR_VERSION >= 3
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
    10
#	define isPy3
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
    11
#endif
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    12
#include <stdlib.h>
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    13
#include <math.h>
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    14
#define DEFERRED_ADDRESS(A) 0
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    15
#if defined(__GNUC__) || defined(sun) || defined(_AIX) || defined(__hpux)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    16
#	define STRICMP strcasecmp
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    17
#elif defined(_MSC_VER)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    18
#	define STRICMP stricmp
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    19
#elif defined(macintosh)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    20
# include <extras.h>
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    21
# define strdup _strdup
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    22
# define STRICMP _stricmp
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    23
#else
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    24
#	error "Don't know how to define STRICMP"
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    25
#endif
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    26
#ifndef max
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    27
#	define max(a,b) ((a)>(b)?(a):(b))
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    28
#endif
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    29
#ifndef min
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    30
#	define min(a,b) ((a)<(b)?(a):(b))
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    31
#endif
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4330
diff changeset
    32
#define VERSION "0.73"
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    33
#define MODULE "_rl_accel"
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    34
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
    35
struct module_state	{
3727
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
    36
	int moduleLineno;
3980
a25f4c0f92bb _rl_accel.c: fix seg fault in traceback handling
robin
parents: 3869
diff changeset
    37
#ifndef isPy3
a25f4c0f92bb _rl_accel.c: fix seg fault in traceback handling
robin
parents: 3869
diff changeset
    38
	PyObject *module;
a25f4c0f92bb _rl_accel.c: fix seg fault in traceback handling
robin
parents: 3869
diff changeset
    39
#endif
3727
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
    40
	};
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
    41
#ifdef isPy3
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
    42
#	define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
4002
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    43
#	define STRNAME "str"
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    44
#	define BYTESNAME "bytes"
3727
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
    45
#else
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
    46
	static struct module_state _state;
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
    47
#	include "bytesobject.h"
3777
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
    48
#	ifndef PyVarObject_HEAD_INIT
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
    49
#		define PyVarObject_HEAD_INIT(type, size) \
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
    50
        	PyObject_HEAD_INIT(type) size,
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
    51
#	endif
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
    52
#	ifndef Py_TYPE
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
    53
#		define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
    54
#	endif
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
    55
#	define PyBytes_AS_STRING	PyString_AS_STRING
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
    56
#	define PyBytes_AsString		PyString_AsString
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
    57
#	define PyBytes_GET_SIZE 	PyString_GET_SIZE
3727
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
    58
#	define GETSTATE(m) (&_state)
4002
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    59
#	define STRNAME "unicode"
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    60
#	define BYTESNAME "str"
3727
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
    61
#endif
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
    62
4002
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    63
#define ERROR_EXIT() {GETSTATE(module)->moduleLineno=__LINE__;goto L_ERR;}
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    64
#define ADD_TB(module,name) _add_TB(module,name)
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    65
#include "compile.h"
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    66
#include "frameobject.h"
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    67
#include "traceback.h"
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    68
static void _add_TB(PyObject *module,char *funcname)
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    69
{
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    70
	int	moduleLineno = GETSTATE(module)->moduleLineno;
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    71
	PyObject *py_globals = NULL;
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    72
	PyCodeObject *py_code = NULL;
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    73
	PyFrameObject *py_frame = NULL;
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    74
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    75
#ifdef isPy3
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    76
	py_globals = PyModule_GetDict(module);
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    77
#else
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    78
	py_globals = PyModule_GetDict(GETSTATE(module)->module);
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    79
#endif
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    80
	if(!py_globals) goto bad;
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    81
	py_code = PyCode_NewEmpty(
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    82
						__FILE__,		/*PyObject *filename,*/
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    83
						funcname,	/*PyObject *name,*/
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    84
						moduleLineno	/*int firstlineno,*/
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    85
						);
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    86
	if(!py_code) goto bad;
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    87
	py_frame = PyFrame_New(
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    88
		PyThreadState_Get(), /*PyThreadState *tstate,*/
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    89
		py_code,			 /*PyCodeObject *code,*/
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    90
		py_globals,			 /*PyObject *globals,*/
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    91
		0					 /*PyObject *locals*/
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    92
		);
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    93
	if(!py_frame) goto bad;
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    94
	py_frame->f_lineno = moduleLineno;
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    95
	PyTraceBack_Here(py_frame);
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    96
bad:
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    97
	Py_XDECREF(py_code);
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    98
	Py_XDECREF(py_frame);
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
    99
}
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   100
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   101
#define a85_0		   1L
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   102
#define a85_1		   85L
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   103
#define a85_2		 7225L
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   104
#define a85_3	   614125L
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   105
#define a85_4	 52200625L
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   106
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   107
PyObject *_a85_encode(PyObject *module, PyObject *args)
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   108
{
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   109
	unsigned char	*inData;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   110
	int				length, blocks, extra, i, k, lim;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   111
	unsigned long	block, res;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   112
	char			*buf;
4002
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   113
	PyObject		*retVal=NULL, *inObj, *_o1=NULL;
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   114
	if(!PyArg_ParseTuple(args, "O", &inObj)) return NULL;
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   115
	if(PyUnicode_Check(inObj)){
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   116
		_o1 = PyUnicode_AsLatin1String(inObj);
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   117
		if(!_o1){
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   118
			PyErr_SetString(PyExc_ValueError,"argument not decodable as latin1");
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   119
			ERROR_EXIT();
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   120
			}
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   121
		inData = PyBytes_AsString(_o1);
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   122
		inObj = _o1;
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   123
		if(!inData){
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   124
			PyErr_SetString(PyExc_ValueError,"argument not converted to internal char string");
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   125
			ERROR_EXIT();
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   126
			}
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   127
		}
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   128
	else if(!PyBytes_Check(inObj)){
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   129
		PyErr_SetString(PyExc_ValueError,"argument should be " BYTESNAME " or latin1 decodable " STRNAME);
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   130
		ERROR_EXIT();
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   131
		}
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   132
	inData = PyBytes_AsString(inObj);
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   133
	length = PyBytes_GET_SIZE(inObj);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   134
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   135
	blocks = length / 4;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   136
	extra = length % 4;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   137
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   138
	buf = (char*)malloc((blocks+1)*5+3);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   139
	lim = 4*blocks;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   140
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   141
	for(k=i=0; i<lim; i += 4){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   142
		/*
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   143
		 * If you evere have trouble with this consider using masking to ensure
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   144
		 * that the shifted quantity is only 8 bits long
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   145
		 */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   146
		block = ((unsigned long)inData[i]<<24)|((unsigned long)inData[i+1]<<16)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   147
				|((unsigned long)inData[i+2]<<8)|((unsigned long)inData[i+3]);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   148
		if (block == 0) buf[k++] = 'z';
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   149
		else {
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   150
			res = block/a85_4;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   151
			buf[k++] = (char)(res+33);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   152
			block -= res*a85_4;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   153
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   154
			res = block/a85_3;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   155
			buf[k++] = (char)(res+33);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   156
			block -= res*a85_3;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   157
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   158
			res = block/a85_2;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   159
			buf[k++] = (char)(res+33);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   160
			block -= res*a85_2;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   161
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   162
			res = block / a85_1;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   163
			buf[k++] = (char)(res+33);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   164
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   165
			buf[k++] = (char)(block-res*a85_1+33);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   166
			}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   167
		}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   168
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   169
	if(extra>0){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   170
		block = 0L;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   171
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   172
		for (i=0; i<extra; i++)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   173
			block += (unsigned long)inData[length-extra+i] << (24-8*i);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   174
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   175
		res = block/a85_4;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   176
		buf[k++] = (char)(res+33);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   177
		if(extra>=1){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   178
			block -= res*a85_4;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   179
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   180
			res = block/a85_3;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   181
			buf[k++] = (char)(res+33);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   182
			if(extra>=2){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   183
				block -= res*a85_3;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   184
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   185
				res = block/a85_2;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   186
				buf[k++] = (char)(res+33);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   187
				if(extra>=3) buf[k++] = (char)((block-res*a85_2)/a85_1+33);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   188
				}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   189
			}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   190
		}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   191
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   192
	buf[k++] = '~';
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   193
	buf[k++] = '>';
3777
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
   194
	retVal = PyUnicode_FromStringAndSize(buf, k);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   195
	free(buf);
4002
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   196
	if(!retVal){
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   197
		PyErr_SetString(PyExc_ValueError,"failed to create return " STRNAME " value" );
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   198
		ERROR_EXIT();
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   199
		}
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   200
L_exit:
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   201
	Py_XDECREF(_o1);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   202
	return retVal;
4002
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   203
L_ERR:
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   204
	ADD_TB(module,"asciiBase85Encode");
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   205
	goto L_exit;
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   206
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   207
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   208
PyObject *_a85_decode(PyObject *module, PyObject *args)
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   209
{
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   210
	unsigned char	*inData, *p, *q, *tmp, *buf;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   211
	unsigned int	length, blocks, extra, k, num, c1, c2, c3, c4, c5;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   212
	static unsigned pad[] = {0,0,0xffffff,0xffff,0xff};
4002
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   213
	PyObject		*retVal=NULL, *inObj, *_o1=NULL;
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   214
	if(!PyArg_ParseTuple(args, "O", &inObj)) return NULL;
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   215
	if(PyUnicode_Check(inObj)){
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   216
		_o1 = PyUnicode_AsLatin1String(inObj);
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   217
		if(!_o1){
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   218
			PyErr_SetString(PyExc_ValueError,"argument not decodable as latin1");
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   219
			ERROR_EXIT();
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   220
			}
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   221
		inData = PyBytes_AsString(_o1);
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   222
		inObj = _o1;
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   223
		if(!inData){
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   224
			PyErr_SetString(PyExc_ValueError,"argument not converted to internal char string");
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   225
			ERROR_EXIT();
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   226
			}
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   227
		}
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   228
	else if(!PyBytes_Check(inObj)){
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   229
		PyErr_SetString(PyExc_ValueError,"argument should be " BYTESNAME " or latin1 decodable " STRNAME);
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   230
		ERROR_EXIT();
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   231
		}
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   232
	inData = PyBytes_AsString(inObj);
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   233
	length = PyBytes_GET_SIZE(inObj);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   234
	for(k=0,q=inData, p=q+length;q<p && (q=(unsigned char*)strchr((const char*)q,'z'));k++, q++);	/*count 'z'*/
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   235
	length += k*4;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   236
	tmp = q = (unsigned char*)malloc(length+1);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   237
	while(inData<p && (k = *inData++)){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   238
		if(isspace(k)) continue;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   239
		if(k=='z'){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   240
			/*turn 'z' into '!!!!!'*/
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   241
			memcpy(q,"!!!!!",5);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   242
			q += 5;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   243
			}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   244
		else
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   245
			*q++ = k;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   246
		}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   247
	inData = tmp;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   248
	length = q - inData;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   249
	buf = inData+length-2;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   250
	if(buf[0]!='~' || buf[1]!='>'){
4002
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   251
		PyErr_SetString(PyExc_ValueError, "Invalid terminator for Ascii Base 85 Stream");
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   252
		free(inData);
4002
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   253
		ERROR_EXIT();
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   254
		}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   255
	length -= 2;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   256
	buf[0] = 0;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   257
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   258
	blocks = length / 5;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   259
	extra = length % 5;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   260
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   261
	buf = (unsigned char*)malloc((blocks+1)*4);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   262
	q = inData+blocks*5;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   263
	for(k=0;inData<q;inData+=5){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   264
		c1 = inData[0]-33;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   265
		c2 = inData[1]-33;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   266
		c3 = inData[2]-33;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   267
		c4 = inData[3]-33;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   268
		c5 = inData[4]-33;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   269
		num = (((c1*85+c2)*85+c3)*85+c4)*85+c5;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   270
		buf[k++] = num>>24;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   271
		buf[k++] = num>>16;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   272
		buf[k++] = num>>8;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   273
		buf[k++] = num;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   274
		}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   275
	if(extra>1){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   276
		c1 = inData[0]-33;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   277
		c2 = extra>=2 ? inData[1]-33: 0;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   278
		c3 = extra>=3 ? inData[2]-33: 0;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   279
		c4 = extra>=4 ? inData[3]-33: 0;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   280
		c5 = 0;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   281
		num = (((c1*85+c2)*85+c3)*85+c4)*85+c5 + pad[extra];
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   282
		if(extra>1){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   283
			buf[k++] = num>>24;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   284
			if(extra>2){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   285
				buf[k++] = num>>16;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   286
				if(extra>3){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   287
					buf[k++] = num>>8;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   288
					}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   289
				}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   290
			}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   291
		}
4002
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   292
	retVal = PyBytes_FromStringAndSize((const char*)buf, k);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   293
	free(buf);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   294
	free(tmp);
4002
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   295
	if(!retVal){
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   296
		PyErr_SetString(PyExc_ValueError,"failed to create return " BYTESNAME " value" );
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   297
		ERROR_EXIT();
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   298
		}
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   299
L_exit:
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   300
	Py_XDECREF(_o1);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   301
	return retVal;
4002
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   302
L_ERR:
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   303
	ADD_TB(module,"asciiBase85Decode");
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   304
	goto L_exit;
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   305
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   306
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   307
static	char* _fp_fmts[]={"%.0f", "%.1f", "%.2f", "%.3f", "%.4f", "%.5f", "%.6f"};
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   308
static	char *_fp_one(PyObject* module,PyObject *pD)
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   309
{
2483
49a62206eba5 _rl_accel: fix fp_str for large magnitudes
rgbecker
parents: 2390
diff changeset
   310
	double	d, ad;
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   311
	static	char s[30];
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   312
	int l;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   313
	char*	dot;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   314
	if((pD=PyNumber_Float(pD))){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   315
		d = PyFloat_AS_DOUBLE(pD);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   316
		Py_DECREF(pD);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   317
		}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   318
	else {
4002
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   319
		PyErr_SetString(PyExc_ValueError, "bad numeric value");
2896
7c4946c7b7b1 rl_addons: restore wrongly checked in stuff after pyHnjmodule.c fix
rgbecker
parents: 2895
diff changeset
   320
		return NULL;
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   321
		}
2483
49a62206eba5 _rl_accel: fix fp_str for large magnitudes
rgbecker
parents: 2390
diff changeset
   322
	ad = fabs(d);
49a62206eba5 _rl_accel: fix fp_str for large magnitudes
rgbecker
parents: 2390
diff changeset
   323
	if(ad<=1.0e-7){
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   324
		s[0]='0';
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   325
		s[1]=0;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   326
		}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   327
	else{
2483
49a62206eba5 _rl_accel: fix fp_str for large magnitudes
rgbecker
parents: 2390
diff changeset
   328
		if(ad>1e20){
4002
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   329
			PyErr_SetString(PyExc_ValueError, "number too large");
2896
7c4946c7b7b1 rl_addons: restore wrongly checked in stuff after pyHnjmodule.c fix
rgbecker
parents: 2895
diff changeset
   330
			return NULL;
2483
49a62206eba5 _rl_accel: fix fp_str for large magnitudes
rgbecker
parents: 2390
diff changeset
   331
			}
49a62206eba5 _rl_accel: fix fp_str for large magnitudes
rgbecker
parents: 2390
diff changeset
   332
		if(ad>1) l = min(max(0,6-(int)log10(ad)),6);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   333
		else l = 6;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   334
		sprintf(s,_fp_fmts[l], d);
2483
49a62206eba5 _rl_accel: fix fp_str for large magnitudes
rgbecker
parents: 2390
diff changeset
   335
		if(l){
49a62206eba5 _rl_accel: fix fp_str for large magnitudes
rgbecker
parents: 2390
diff changeset
   336
			l = strlen(s)-1;
49a62206eba5 _rl_accel: fix fp_str for large magnitudes
rgbecker
parents: 2390
diff changeset
   337
			while(l && s[l]=='0') l--;
49a62206eba5 _rl_accel: fix fp_str for large magnitudes
rgbecker
parents: 2390
diff changeset
   338
			if(s[l]=='.' || s[l]==',') s[l]=0;
49a62206eba5 _rl_accel: fix fp_str for large magnitudes
rgbecker
parents: 2390
diff changeset
   339
			else {
49a62206eba5 _rl_accel: fix fp_str for large magnitudes
rgbecker
parents: 2390
diff changeset
   340
				s[l+1]=0;
49a62206eba5 _rl_accel: fix fp_str for large magnitudes
rgbecker
parents: 2390
diff changeset
   341
				if(s[0]=='0' && (s[1]=='.'||s[1]==',')){
49a62206eba5 _rl_accel: fix fp_str for large magnitudes
rgbecker
parents: 2390
diff changeset
   342
					if(s[1]==',') s[1] = '.';
49a62206eba5 _rl_accel: fix fp_str for large magnitudes
rgbecker
parents: 2390
diff changeset
   343
					return s+1;
49a62206eba5 _rl_accel: fix fp_str for large magnitudes
rgbecker
parents: 2390
diff changeset
   344
					}
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   345
				}
2483
49a62206eba5 _rl_accel: fix fp_str for large magnitudes
rgbecker
parents: 2390
diff changeset
   346
			if((dot=strchr(s,','))) *dot = '.';
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   347
			}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   348
		}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   349
	return s;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   350
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   351
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   352
PyObject *_fp_str(PyObject *module, PyObject *args)
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   353
{
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   354
	int				aL;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   355
	PyObject		*retVal;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   356
	char			*pD;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   357
	char			*buf, *pB;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   358
	int				i;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   359
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   360
	if((aL=PySequence_Length(args))>=0){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   361
		if(aL==1){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   362
			retVal = PySequence_GetItem(args,0);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   363
			if((i=PySequence_Length(retVal))>=0){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   364
				aL = i;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   365
				args = retVal;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   366
				}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   367
			else PyErr_Clear();
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   368
			Py_DECREF(retVal);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   369
			}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   370
		buf=malloc(31*aL);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   371
		pB = buf;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   372
		for(i=0;i<aL;i++){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   373
			retVal = PySequence_GetItem(args,i);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   374
			if(retVal){
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   375
				pD = _fp_one(module,retVal);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   376
				Py_DECREF(retVal);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   377
				}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   378
			else pD = NULL;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   379
			if(!pD){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   380
				free(buf);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   381
				return NULL;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   382
				}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   383
			if(pB!=buf){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   384
				*pB++ = ' ';
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   385
				}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   386
			strcpy(pB,pD);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   387
			pB = pB + strlen(pB);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   388
			}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   389
		*pB = 0;
3765
a7e7cd6e0003 renderPM.py now works to produce a pmout at least
robin
parents: 3730
diff changeset
   390
#ifdef isPy3
a7e7cd6e0003 renderPM.py now works to produce a pmout at least
robin
parents: 3730
diff changeset
   391
		retVal = PyUnicode_FromString(buf);
a7e7cd6e0003 renderPM.py now works to produce a pmout at least
robin
parents: 3730
diff changeset
   392
#else
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   393
		retVal = PyBytes_FromString(buf);
3765
a7e7cd6e0003 renderPM.py now works to produce a pmout at least
robin
parents: 3730
diff changeset
   394
#endif
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   395
		free(buf);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   396
		return retVal;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   397
		}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   398
	else {
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   399
		PyErr_Clear();
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   400
		PyArg_ParseTuple(args, "O:_fp_str", &retVal);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   401
		return NULL;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   402
		}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   403
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   404
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   405
static PyObject *_escapePDF(unsigned char* text, int textlen)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   406
{
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   407
	unsigned char*	out = PyMem_Malloc((textlen<<2)+1);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   408
	int				j=0, i=0;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   409
	char			buf[4];
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   410
	PyObject*		ret;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   411
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   412
	while(i<textlen){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   413
		unsigned char c = text[i++];
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   414
		if(c<32 || c>=127){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   415
			sprintf(buf,"%03o",c);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   416
			out[j++] = '\\';
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   417
			out[j++] = buf[0];
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   418
			out[j++] = buf[1];
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   419
			out[j++] = buf[2];
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   420
			}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   421
		else {
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   422
			if(c=='\\' || c=='(' || c==')') out[j++] = '\\';
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   423
			out[j++] = c;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   424
			}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   425
		}
3777
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
   426
#ifdef isPy3
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
   427
	ret = PyUnicode_FromStringAndSize((const char *)out,j);
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
   428
#else
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   429
	ret = PyBytes_FromStringAndSize((const char *)out,j);
3777
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
   430
#endif
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   431
	PyMem_Free(out);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   432
	return ret;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   433
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   434
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   435
static PyObject *escapePDF(PyObject *module, PyObject* args)
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   436
{
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   437
	unsigned char	*text;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   438
	int				textLen;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   439
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   440
	if (!PyArg_ParseTuple(args, "s#:escapePDF", &text, &textLen)) return NULL;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   441
	return _escapePDF(text,textLen);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   442
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   443
3778
1c9196ca9795 exported name changes
robin
parents: 3777
diff changeset
   444
static PyObject *sameFrag(PyObject *module, PyObject* args)
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   445
{
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   446
	PyObject *f, *g;
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4330
diff changeset
   447
	static char *names[] = {"fontName", "fontSize", "textColor", "rise", "us_lines", "link", "backColor", NULL};
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   448
	int	r=0, t;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   449
	char **p;
3778
1c9196ca9795 exported name changes
robin
parents: 3777
diff changeset
   450
	if (!PyArg_ParseTuple(args, "OO:sameFrag", &f, &g)) return NULL;
2665
1b1ff5f0c6cb _rl_accel.c: version 0.58 _sameFrag supports lineBreak
rgbecker
parents: 2651
diff changeset
   451
	if(PyObject_HasAttrString(f,"cbDefn")||PyObject_HasAttrString(g,"cbDefn")
1b1ff5f0c6cb _rl_accel.c: version 0.58 _sameFrag supports lineBreak
rgbecker
parents: 2651
diff changeset
   452
		|| PyObject_HasAttrString(f,"lineBreak")||PyObject_HasAttrString(g,"lineBreak")) goto L0;
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   453
	for(p=names;*p;p++){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   454
		PyObject *fa, *ga;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   455
		fa = PyObject_GetAttrString(f,*p);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   456
		ga = PyObject_GetAttrString(g,*p);
2649
07513253980c _rl_accel.c: fix _sameFrag to allow missing attributes
rgbecker
parents: 2643
diff changeset
   457
		if(fa && ga){
3777
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
   458
#ifdef	isPy3
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   459
			t = PyObject_RichCompareBool(fa,ga,Py_NE);
3777
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
   460
#else
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
   461
			t = PyObject_Compare(fa,ga);
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
   462
#endif
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   463
			Py_DECREF(fa);
2649
07513253980c _rl_accel.c: fix _sameFrag to allow missing attributes
rgbecker
parents: 2643
diff changeset
   464
			Py_DECREF(ga);
07513253980c _rl_accel.c: fix _sameFrag to allow missing attributes
rgbecker
parents: 2643
diff changeset
   465
			if(PyErr_Occurred()) goto L1;
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   466
			}
2649
07513253980c _rl_accel.c: fix _sameFrag to allow missing attributes
rgbecker
parents: 2643
diff changeset
   467
		else{
07513253980c _rl_accel.c: fix _sameFrag to allow missing attributes
rgbecker
parents: 2643
diff changeset
   468
			t = fa==ga ? 0 : 1;
07513253980c _rl_accel.c: fix _sameFrag to allow missing attributes
rgbecker
parents: 2643
diff changeset
   469
			Py_XDECREF(fa);
07513253980c _rl_accel.c: fix _sameFrag to allow missing attributes
rgbecker
parents: 2643
diff changeset
   470
			Py_XDECREF(ga);
07513253980c _rl_accel.c: fix _sameFrag to allow missing attributes
rgbecker
parents: 2643
diff changeset
   471
			PyErr_Clear();
07513253980c _rl_accel.c: fix _sameFrag to allow missing attributes
rgbecker
parents: 2643
diff changeset
   472
			}
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   473
		if(t) goto L0;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   474
		}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   475
	r = 1;
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   476
L0:	return PyBool_FromLong((long)r);
2649
07513253980c _rl_accel.c: fix _sameFrag to allow missing attributes
rgbecker
parents: 2643
diff changeset
   477
L1:	return NULL;
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   478
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   479
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   480
static PyObject *ttfonts_calcChecksum(PyObject *module, PyObject* args)
2712
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   481
{
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   482
	unsigned char	*data;
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   483
	int				dataLen;
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   484
	unsigned long	Sum = 0L;
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   485
	unsigned char	*EndPtr;
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   486
	unsigned long n;
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   487
	int leftover;
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   488
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   489
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   490
	if (!PyArg_ParseTuple(args, "s#:calcChecksum", &data, &dataLen)) return NULL;
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   491
	EndPtr = data + (dataLen & ~3);
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   492
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   493
	/*full ULONGs*/
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   494
	while(data < EndPtr){
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   495
		n = ((*data++) << 24);
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   496
		n += ((*data++) << 16);
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   497
		n += ((*data++) << 8);
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   498
		n += ((*data++));
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   499
		Sum += n;
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   500
		}
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   501
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   502
	/*pad with zeros*/
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   503
	leftover = dataLen & 3;
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   504
	if(leftover){
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   505
		n = ((*data++) << 24);
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   506
		if (leftover>1) n += ((*data++) << 16);
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   507
		if (leftover>2) n += ((*data++) << 8);
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   508
		Sum += n;
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   509
		}
5b60be1d9a46 _rl_accel.c: keep legacy checksum code for older reportlab python
rgbecker
parents: 2710
diff changeset
   510
2710
b3cbf74c0f5d _rl_accel: return ttfonts checksums as L
rgbecker
parents: 2665
diff changeset
   511
	return PyLong_FromUnsignedLong(Sum&0xFFFFFFFFU);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   512
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   513
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   514
static PyObject *ttfonts_add32(PyObject *module, PyObject* args)
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   515
{
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   516
	unsigned long x, y;
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   517
	if(!PyArg_ParseTuple(args, "kk:add32", &x, &y)) return NULL;
3777
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
   518
	return PyLong_FromUnsignedLong((x+y)&0xFFFFFFFFU);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   519
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   520
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   521
static PyObject *hex32(PyObject *module, PyObject* args)
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   522
{
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   523
	unsigned long x;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   524
	char	buf[20];
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   525
	if(!PyArg_ParseTuple(args, "k:hex32", &x)) return NULL;
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   526
	sprintf(buf,"0X%8.8lX",x);
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   527
	return PyUnicode_FromString(buf);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   528
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   529
2603
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   530
static PyObject *_GetExcValue(void)
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   531
{
2610
eed2609cb7a4 rl_accel: fixed GetExcV
rgbecker
parents: 2607
diff changeset
   532
	PyObject *type = NULL, *value = NULL, *tb = NULL, *result=NULL;
2599
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   533
	PyErr_Fetch(&type, &value, &tb);
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   534
	PyErr_NormalizeException(&type, &value, &tb);
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   535
	if(PyErr_Occurred()) goto L_BAD;
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   536
	if(!value){
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   537
		value = Py_None;
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   538
		Py_INCREF(value);
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   539
		}
2610
eed2609cb7a4 rl_accel: fixed GetExcV
rgbecker
parents: 2607
diff changeset
   540
	Py_XINCREF(value);
2599
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   541
	result = value;
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   542
L_BAD:
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   543
	Py_XDECREF(type);
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   544
	Py_XDECREF(value);
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   545
	Py_XDECREF(tb);
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   546
	return result;
2603
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   547
}
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   548
static PyObject *_GetAttrString(PyObject *obj, char *name)
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   549
{
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   550
	PyObject *res = PyObject_GetAttrString(obj, name);
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   551
	if(!res) PyErr_SetString(PyExc_AttributeError, name);
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   552
	return res;
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   553
}
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   554
4267
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   555
/* Get a UTF8 encoded string buffer, the return value is the PyObject
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   556
   holding the memory for the buffer and should be decrefed to free
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   557
   memory */
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   558
static PyObject *_GetStringBuf(PyObject *obj, char **buf)
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   559
{
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   560
	PyObject *res;
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   561
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   562
	if(PyUnicode_Check(obj)){
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   563
#ifdef	isPy3
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   564
		res = obj;
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   565
		Py_INCREF(res);
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   566
		*buf = PyUnicode_AsUTF8(res);
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   567
#else
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   568
		res = PyUnicode_AsUTF8String(obj);
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   569
		if (!res) {
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   570
			PyErr_SetString(PyExc_ValueError,
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   571
					"encode to UTF8 bytes failed");
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   572
			return NULL;
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   573
		}
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   574
		*buf = PyBytes_AsString(res);
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   575
#endif
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   576
		}
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   577
	else if(PyBytes_Check(obj)){
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   578
		res = obj;
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   579
		Py_INCREF(res);
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   580
		*buf = PyBytes_AsString(res);
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   581
		}
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   582
	else{
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   583
		PyErr_SetString(PyExc_ValueError,
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   584
				"require bytes or unicode object");
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   585
		return NULL;
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   586
		}
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   587
	return res;
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   588
}
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   589
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   590
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   591
static PyObject *unicode2T1(PyObject *module, PyObject *args, PyObject *kwds)
2603
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   592
{
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   593
	long		i, j, _i1, _i2;
3869
71791c3c0aa7 _rl_accel.c: fix & improve unicode2T1 & instanceStringWidthT1
robin
parents: 3866
diff changeset
   594
	PyObject	*R, *font, *res, *utext=NULL, *fonts=NULL,
2896
7c4946c7b7b1 rl_addons: restore wrongly checked in stuff after pyHnjmodule.c fix
rgbecker
parents: 2895
diff changeset
   595
				*_o1 = NULL, *_o2 = NULL, *_o3 = NULL;
2599
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   596
	static char *argnames[] = {"utext","fonts",NULL};
4267
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   597
	PyObject	*encObj = NULL;
2604
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   598
	char		*encStr;
2599
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   599
	if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", argnames, &utext, &fonts)) return NULL;
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   600
	Py_INCREF(utext);
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   601
	Py_INCREF(fonts);
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   602
	R = Py_None; Py_INCREF(Py_None);
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   603
	font = Py_None; Py_INCREF(Py_None);
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   604
2896
7c4946c7b7b1 rl_addons: restore wrongly checked in stuff after pyHnjmodule.c fix
rgbecker
parents: 2895
diff changeset
   605
2603
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   606
	_o2 = PyList_New(0); if(!_o2) ERROR_EXIT();
2599
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   607
	Py_DECREF(R);
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   608
	R = _o2;
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   609
	_o2 = NULL;
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   610
2603
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   611
	_o2 = PySequence_GetItem(fonts,0); if(!_o2) ERROR_EXIT();
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   612
	_o1 = PySequence_GetSlice(fonts, 1, 0x7fffffff); if(!_o1) ERROR_EXIT();
2599
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   613
	Py_DECREF(font);
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   614
	font = _o2;
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   615
	Py_DECREF(fonts);
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   616
	fonts = _o1;
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   617
	_o1 = _o2 = NULL;
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   618
2603
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   619
	_o2 = _GetAttrString(font, "encName"); if(!_o2) ERROR_EXIT();
4267
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   620
	encObj = _GetStringBuf(_o2, &encStr);
3869
71791c3c0aa7 _rl_accel.c: fix & improve unicode2T1 & instanceStringWidthT1
robin
parents: 3866
diff changeset
   621
	Py_DECREF(_o2);
71791c3c0aa7 _rl_accel.c: fix & improve unicode2T1 & instanceStringWidthT1
robin
parents: 3866
diff changeset
   622
	_o2 = NULL;
4267
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   623
	if (!encObj) ERROR_EXIT();
2604
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   624
	if(strstr(encStr,"UCS-2")) encStr = "UTF16";
2599
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   625
2604
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   626
	while((_i1=PyObject_IsTrue(utext))>0){
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   627
		if((_o1 = PyUnicode_AsEncodedString(utext, encStr, NULL))){
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   628
			_o2 = PyTuple_New(2); if(!_o2) ERROR_EXIT();
2599
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   629
			Py_INCREF(font);
2604
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   630
			PyTuple_SET_ITEM(_o2, 0, font);
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   631
			PyTuple_SET_ITEM(_o2, 1, _o1);
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   632
			_o1 = NULL;
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   633
			if(PyList_Append(R, _o2)) ERROR_EXIT();
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   634
			Py_DECREF(_o2); _o2 = NULL;
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   635
			break;
2599
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   636
			}
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   637
		else{
2604
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   638
			Py_XDECREF(_o1); _o1 = NULL;
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   639
			if(!PyErr_ExceptionMatches(PyExc_UnicodeEncodeError)) ERROR_EXIT();
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   640
			_o1 = _GetExcValue(); if(!_o1) ERROR_EXIT();
2610
eed2609cb7a4 rl_accel: fixed GetExcV
rgbecker
parents: 2607
diff changeset
   641
			PyErr_Clear();
2604
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   642
			_o2 = _GetAttrString(_o1, "args"); if(!_o2) ERROR_EXIT();
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   643
			Py_DECREF(_o1);
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   644
			_o1 = PySequence_GetSlice(_o2, 2, 4); if(!_o1) ERROR_EXIT();
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   645
			Py_DECREF(_o2);
3831
cf9b0da67c42 _rl_accel.c: allow font.encName to be bytes
robin
parents: 3786
diff changeset
   646
			_o2 = PySequence_GetItem(_o1, 0); if(!_o2) ERROR_EXIT();
cf9b0da67c42 _rl_accel.c: allow font.encName to be bytes
robin
parents: 3786
diff changeset
   647
			i = PyLong_AsLong(_o2); if(PyErr_Occurred()) ERROR_EXIT();
cf9b0da67c42 _rl_accel.c: allow font.encName to be bytes
robin
parents: 3786
diff changeset
   648
			Py_DECREF(_o2);
2610
eed2609cb7a4 rl_accel: fixed GetExcV
rgbecker
parents: 2607
diff changeset
   649
3831
cf9b0da67c42 _rl_accel.c: allow font.encName to be bytes
robin
parents: 3786
diff changeset
   650
			_o2 = PySequence_GetItem(_o1, 1); if(!_o1) ERROR_EXIT();
cf9b0da67c42 _rl_accel.c: allow font.encName to be bytes
robin
parents: 3786
diff changeset
   651
			j = PyLong_AsLong(_o2); if(PyErr_Occurred()) ERROR_EXIT();
cf9b0da67c42 _rl_accel.c: allow font.encName to be bytes
robin
parents: 3786
diff changeset
   652
			Py_DECREF(_o2);
2610
eed2609cb7a4 rl_accel: fixed GetExcV
rgbecker
parents: 2607
diff changeset
   653
2604
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   654
			Py_DECREF(_o1); _o2 = _o1 = 0;
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   655
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   656
			if(i){
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   657
				_o1 = PySequence_GetSlice(utext, 0, i); if(!_o1) ERROR_EXIT();
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   658
				_o2 = PyUnicode_AsEncodedString(_o1, encStr, NULL); if(!_o2) ERROR_EXIT();
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   659
				Py_DECREF(_o1);
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   660
				_o1 = PyTuple_New(2); if(!_o1) ERROR_EXIT();
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   661
				Py_INCREF(font);
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   662
				PyTuple_SET_ITEM(_o1, 0, font);
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   663
				PyTuple_SET_ITEM(_o1, 1, _o2);
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   664
				_o2 = NULL;
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   665
				if(PyList_Append(R, _o1)) ERROR_EXIT();
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   666
				Py_DECREF(_o1); _o1 = NULL;
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   667
				}
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   668
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   669
			_i2 = PyObject_IsTrue(fonts); if(_i2<0) ERROR_EXIT();
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   670
			if(_i2){
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   671
				_o1 = PySequence_GetSlice(utext, i, j); if(!_o1) ERROR_EXIT();
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   672
				_o2 = PyTuple_New(2); if(!_o2) ERROR_EXIT();
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   673
				PyTuple_SET_ITEM(_o2, 0, _o1);
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   674
				Py_INCREF(fonts);
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   675
				PyTuple_SET_ITEM(_o2, 1, fonts);
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   676
				_o1 = unicode2T1(module,_o2,NULL); if(!_o1) ERROR_EXIT();
2604
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   677
				Py_DECREF(_o2); _o2 = 0;
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   678
				_o3 = PyTuple_New(1); if(!_o3) ERROR_EXIT();
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   679
				PyTuple_SET_ITEM(_o3, 0, _o1);
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   680
				_o1 = _GetAttrString(R, "extend"); if(!_o1) ERROR_EXIT();
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   681
				_o2 = PyObject_CallObject(_o1, _o3); if(!_o2) ERROR_EXIT();
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   682
				Py_DECREF(_o1);
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   683
				Py_DECREF(_o3);
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   684
				Py_DECREF(_o2); _o1 = _o2 = _o3 = NULL;
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   685
				}
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   686
			else{
3421
d6f26fcd26d2 _rl_accel.c: remove pdfmetrics.py variable caching (except for _notdefChar/Font when used with older pdfmetrics.py)
rgbecker
parents: 3420
diff changeset
   687
				_o3 = _GetAttrString(font,"_notdefChar");
3727
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
   688
				if(!_o3) ERROR_EXIT();
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   689
				_o2 = PyLong_FromLong((j - i)); if(!_o2) ERROR_EXIT();
3727
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
   690
				_o1 = PyNumber_Multiply(_o3, _o2); if(!_o1) ERROR_EXIT();
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
   691
				Py_DECREF(_o2); Py_DECREF(_o3); _o2=_o3=NULL;
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
   692
				_o2 = PyTuple_New(2); if(!_o2) ERROR_EXIT();
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
   693
				_o3 = _GetAttrString(font,"_notdefFont"); if(!_o3) ERROR_EXIT();
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
   694
				PyTuple_SET_ITEM(_o2, 0, _o3);
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
   695
				PyTuple_SET_ITEM(_o2, 1, _o1);
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
   696
				Py_INCREF(_o3); _o3=NULL;
2896
7c4946c7b7b1 rl_addons: restore wrongly checked in stuff after pyHnjmodule.c fix
rgbecker
parents: 2895
diff changeset
   697
				_o1 = NULL;
2604
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   698
				if(PyList_Append(R, _o2)) ERROR_EXIT();
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   699
				Py_DECREF(_o2); _o2 = NULL;
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   700
				}
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   701
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   702
			_o1 = PySequence_GetSlice(utext, j, 0x7fffffff); if(!_o1) ERROR_EXIT();
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   703
			Py_DECREF(utext);
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   704
			utext = _o1;
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   705
			_o1 = NULL;
2599
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   706
			}
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   707
		}
2604
aae3fdaa49e6 _rl_accel.c: added working _instanceStringWidthU
rgbecker
parents: 2603
diff changeset
   708
	if(_i1<0) ERROR_EXIT();
2599
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   709
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   710
	Py_INCREF(R);
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   711
	res = R;
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   712
	goto L_OK;
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   713
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   714
L_ERR:
3727
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
   715
	ADD_TB(module,"unicode2T1");
2599
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   716
	Py_XDECREF(_o1);
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   717
	Py_XDECREF(_o2);
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   718
	Py_XDECREF(_o3);
2600
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   719
	res = NULL;
2599
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   720
L_OK:
4267
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   721
	Py_XDECREF(encObj);
2599
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   722
	Py_DECREF(R);
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   723
	Py_DECREF(font);
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   724
	Py_DECREF(utext);
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   725
	Py_DECREF(fonts);
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   726
	return res;
2603
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   727
}
3778
1c9196ca9795 exported name changes
robin
parents: 3777
diff changeset
   728
static PyObject *instanceStringWidthT1(PyObject *module, PyObject *args, PyObject *kwds)
2603
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   729
{
3730
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
   730
	PyObject *L=0, *t=0, *f=0, *self, *text, *size, *res,
2600
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   731
				*encoding = 0, *_o1 = 0, *_o2 = 0, *_o3 = 0;
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   732
	unsigned char *b;
4267
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   733
	PyObject *encObj = NULL;
3866
94cfccfe8a25 _rl_accel.c: attempted efficiency imporvement in instanceStringWidthT1
robin
parents: 3863
diff changeset
   734
	const char *encStr;
2600
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   735
	int n, m, i, j, s, _i1;
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   736
	static char *argnames[]={"self","text","size","encoding",0};
3866
94cfccfe8a25 _rl_accel.c: attempted efficiency imporvement in instanceStringWidthT1
robin
parents: 3863
diff changeset
   737
	if(!PyArg_ParseTupleAndKeywords(args, kwds, "OOO|O", argnames, &self, &text, &size, &encoding)) return 0;
2600
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   738
	Py_INCREF(text);
3866
94cfccfe8a25 _rl_accel.c: attempted efficiency imporvement in instanceStringWidthT1
robin
parents: 3863
diff changeset
   739
	if(!encoding) encStr="utf8";
4267
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   740
	else {
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   741
		encObj = _GetStringBuf(encoding, &encStr);
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   742
		if(!encObj) ERROR_EXIT();
3866
94cfccfe8a25 _rl_accel.c: attempted efficiency imporvement in instanceStringWidthT1
robin
parents: 3863
diff changeset
   743
		}
2600
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   744
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   745
	if(!PyUnicode_Check(text)){
3866
94cfccfe8a25 _rl_accel.c: attempted efficiency imporvement in instanceStringWidthT1
robin
parents: 3863
diff changeset
   746
		if(PyBytes_Check(text)){
94cfccfe8a25 _rl_accel.c: attempted efficiency imporvement in instanceStringWidthT1
robin
parents: 3863
diff changeset
   747
			_o1=PyUnicode_Decode(PyBytes_AS_STRING(text), PyBytes_GET_SIZE(text), encStr,"strict");
94cfccfe8a25 _rl_accel.c: attempted efficiency imporvement in instanceStringWidthT1
robin
parents: 3863
diff changeset
   748
			if(!_o1) ERROR_EXIT();
94cfccfe8a25 _rl_accel.c: attempted efficiency imporvement in instanceStringWidthT1
robin
parents: 3863
diff changeset
   749
			Py_DECREF(text);
94cfccfe8a25 _rl_accel.c: attempted efficiency imporvement in instanceStringWidthT1
robin
parents: 3863
diff changeset
   750
			text = _o1;
94cfccfe8a25 _rl_accel.c: attempted efficiency imporvement in instanceStringWidthT1
robin
parents: 3863
diff changeset
   751
			_o1 = NULL;
94cfccfe8a25 _rl_accel.c: attempted efficiency imporvement in instanceStringWidthT1
robin
parents: 3863
diff changeset
   752
			}
94cfccfe8a25 _rl_accel.c: attempted efficiency imporvement in instanceStringWidthT1
robin
parents: 3863
diff changeset
   753
		else{
4002
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
   754
			PyErr_SetString(PyExc_ValueError, "invalid type for argument text");
3866
94cfccfe8a25 _rl_accel.c: attempted efficiency imporvement in instanceStringWidthT1
robin
parents: 3863
diff changeset
   755
			ERROR_EXIT();
94cfccfe8a25 _rl_accel.c: attempted efficiency imporvement in instanceStringWidthT1
robin
parents: 3863
diff changeset
   756
			}
2600
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   757
		}
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   758
2603
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   759
	_o3 = PyList_New(1); if(!_o3) ERROR_EXIT();
2600
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   760
	Py_INCREF(self);
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   761
	PyList_SET_ITEM(_o3, 0, self);
2603
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   762
	_o2 = _GetAttrString(self, "substitutionFonts"); if(!_o2) ERROR_EXIT();
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   763
	_o1 = PyNumber_Add(_o3, _o2); if(!_o1) ERROR_EXIT();
2600
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   764
	Py_DECREF(_o3); _o3 = 0;
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   765
	Py_DECREF(_o2); _o2 = NULL;
2603
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   766
	_o3 = PyTuple_New(2); if(!_o3) ERROR_EXIT();
2600
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   767
	Py_INCREF(text);
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   768
	PyTuple_SET_ITEM(_o3, 0, text);
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   769
	PyTuple_SET_ITEM(_o3, 1, _o1);
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   770
	_o1 = NULL;
2896
7c4946c7b7b1 rl_addons: restore wrongly checked in stuff after pyHnjmodule.c fix
rgbecker
parents: 2895
diff changeset
   771
	_o2 = unicode2T1(module,_o3,NULL); if(!_o2) ERROR_EXIT();
2600
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   772
	Py_DECREF(_o3); _o3 = NULL;
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   773
	L = _o2;
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   774
	_o2 = NULL;
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   775
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   776
	n = PyList_GET_SIZE(L);
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   777
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   778
	for(s=i=0;i<n;++i){
2603
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   779
		_o1 = PyList_GetItem(L,i); if(!_o1) ERROR_EXIT();
2600
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   780
		Py_INCREF(_o1);
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   781
2603
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   782
		_o2 = PySequence_GetItem(_o1, 0); if(!_o2) ERROR_EXIT();
3863
53cdee53a6f9 _rl_accel.c: fix refcount bug in instanceWidthT1
robin
parents: 3831
diff changeset
   783
		Py_XDECREF(f);
2600
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   784
		f = _o2;
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   785
		_o2 = NULL;
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   786
2603
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   787
		_o2 = _GetAttrString(f, "widths"); if(!_o2) ERROR_EXIT();
2600
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   788
		Py_DECREF(f);
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   789
		f = _o2;
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   790
		_o2 = NULL;
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   791
2603
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   792
		_o2 = PySequence_GetItem(_o1, 1); if(!_o2) ERROR_EXIT();
3863
53cdee53a6f9 _rl_accel.c: fix refcount bug in instanceWidthT1
robin
parents: 3831
diff changeset
   793
		Py_XDECREF(t);
2600
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   794
		t = _o2;
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   795
		Py_DECREF(_o1);
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   796
		_o1 = _o2 = NULL;
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   797
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   798
		m = PyBytes_Size(t);
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   799
		b = (unsigned char*)PyBytes_AS_STRING(t);
2600
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   800
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   801
		for(j=0;j<m;++j){
2603
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   802
			_i1 = (long)(b[j]);
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   803
			_o2 = PyList_GetItem(f,_i1); if(!_o2) {PyErr_Format(PyExc_IndexError,"widths index %d out of range",_i1);ERROR_EXIT();}
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   804
			_i1 = PyLong_AsLong(_o2);
2600
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   805
			_o2 = NULL;	/*we borrowed this*/
2603
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   806
			if(PyErr_Occurred()) ERROR_EXIT();
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   807
			s += _i1;
2600
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   808
			}
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   809
		}
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   810
2603
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   811
	_o1 = PyFloat_FromDouble((s * 0.001)); if(!_o1) ERROR_EXIT();
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   812
	res = PyNumber_Multiply(_o1, size); if(!res) ERROR_EXIT();
2605
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   813
	Py_DECREF(_o1);
2600
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   814
	goto L_OK;
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   815
L_ERR:
3786
5008a8b9567b fix usage of instanceStringWidthT1
robin
parents: 3778
diff changeset
   816
	ADD_TB(module,"instanceStringWidthT1");
2600
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   817
	Py_XDECREF(_o1);
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   818
	Py_XDECREF(_o2);
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   819
	Py_XDECREF(_o3);
2603
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   820
	res = NULL;
2600
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   821
L_OK:
4267
df9e44b0db35 fix segfault in _rl_accel.c; fix contributed by Neil Schemenauer as issue #78
robin
parents: 4246
diff changeset
   822
	Py_XDECREF(encObj);
3730
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
   823
	Py_XDECREF(L);
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
   824
	Py_XDECREF(t);
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
   825
	Py_XDECREF(f);
2600
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   826
	Py_DECREF(text);
50c12d3b940c _rl_accel.c: more version2 funcs
rgbecker
parents: 2599
diff changeset
   827
	return res;
2603
562a1ac1cd39 _rl_accel.c: added initial _instanceStringWidthU
rgbecker
parents: 2600
diff changeset
   828
}
3778
1c9196ca9795 exported name changes
robin
parents: 3777
diff changeset
   829
static PyObject *instanceStringWidthTTF(PyObject *module, PyObject *args, PyObject *kwds)
2605
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   830
{
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   831
	PyObject *self, *text, *size, *res,
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   832
				*encoding = 0, *_o1=NULL, *_o2=NULL, *_o3=NULL;
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   833
	Py_UNICODE *b;
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   834
	int n, i;
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   835
	double s, _d1, dw;
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   836
	static char *argnames[]={"self","text","size","encoding",0};
2607
aca8a844b645 _rl_accel.c: fix encoding argument getting
rgbecker
parents: 2605
diff changeset
   837
	if(!PyArg_ParseTupleAndKeywords(args, kwds, "OOO|O", argnames, &self, &text, &size, &_o1)) return 0;
2605
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   838
	Py_INCREF(text);
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   839
	if(_o1){
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   840
		encoding = _o1;
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   841
		_o1 = NULL;
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   842
		Py_INCREF(encoding);
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   843
		}
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   844
	else{
3730
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
   845
		_o1 = PyUnicode_FromString("utf8"); if(!_o1) ERROR_EXIT();
2605
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   846
		encoding = _o1;
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   847
		_o1 = NULL;
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   848
		}
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   849
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   850
	if(!PyUnicode_Check(text)){
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   851
		i = PyObject_IsTrue(encoding); if(i<0) ERROR_EXIT();
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   852
		if(!i){
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   853
			Py_DECREF(encoding);
3730
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
   854
			encoding = PyUnicode_FromString("utf8"); if(!encoding) ERROR_EXIT();
2605
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   855
			}
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   856
		_o1 = _GetAttrString(text, "decode"); if(!_o1) ERROR_EXIT();
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   857
		_o3 = PyTuple_New(1); if(!_o3) ERROR_EXIT();
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   858
		Py_INCREF(encoding);
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   859
		PyTuple_SET_ITEM(_o3, 0, encoding);
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   860
		_o2 = PyObject_CallObject(_o1, _o3); if(!_o2) ERROR_EXIT();
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   861
		Py_DECREF(_o1);
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   862
		Py_DECREF(_o3); _o1 = _o3 = NULL;
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   863
		Py_DECREF(text);
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   864
		text = _o2; /*no _o2=NULL as we assign there straight away*/ 
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   865
		}
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   866
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   867
	/*self.face.charWidths --> _o1, self.face.defaultWidth --> _o3*/
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   868
	_o2 = _GetAttrString(self, "face"); if(!_o2) ERROR_EXIT();
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   869
	_o1 = _GetAttrString(_o2, "charWidths"); if(!_o1) ERROR_EXIT(); if(!PyDict_Check(_o1)){PyErr_SetString(PyExc_TypeError, "TTFontFace instance charWidths is not a dict");ERROR_EXIT();}
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   870
	_o3 = _GetAttrString(_o2, "defaultWidth"); if(!_o3) ERROR_EXIT();
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   871
	Py_DECREF(_o2); _o2 = NULL;
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   872
	dw = PyFloat_AsDouble(_o3);
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   873
	if(PyErr_Occurred()) ERROR_EXIT();
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   874
	Py_DECREF(_o3);	_o3=NULL;
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   875
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   876
	n = PyUnicode_GET_SIZE(text);
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   877
	b = PyUnicode_AS_UNICODE(text);
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   878
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   879
	for(s=i=0;i<n;++i){
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   880
		_o3 = PyLong_FromLong((long)b[i]); if(!_o3) ERROR_EXIT();
2605
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   881
		_o2 = PyDict_GetItem(_o1,_o3);
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   882
		Py_DECREF(_o3); _o3 = NULL;
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   883
		if(!_o2) _d1 = dw;
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   884
		else{
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   885
			_d1 = PyFloat_AsDouble(_o2);
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   886
			_o2=NULL;	/*no decref as we borrowed it*/
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   887
			if(PyErr_Occurred()) ERROR_EXIT();
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   888
			}
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   889
		s += _d1;
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   890
		}
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   891
	Py_DECREF(_o1);
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   892
	_o1 = PyFloat_FromDouble((s * 0.001)); if(!_o1) ERROR_EXIT();
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   893
	res = PyNumber_Multiply(_o1, size); if(!res) ERROR_EXIT();
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   894
	Py_DECREF(_o1);
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   895
	goto L_OK;
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   896
L_ERR:
3778
1c9196ca9795 exported name changes
robin
parents: 3777
diff changeset
   897
	ADD_TB(module,"instanceStringWidthTTF");
2605
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   898
	Py_XDECREF(_o1);
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   899
	Py_XDECREF(_o2);
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   900
	Py_XDECREF(_o3);
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   901
	res = NULL;
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   902
L_OK:
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   903
	Py_DECREF(text);
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   904
	Py_DECREF(encoding);
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   905
	return res;
ad7b5468898f rl_accel: added _instanceStringWidthTTF + minor changes & some tests
rgbecker
parents: 2604
diff changeset
   906
}
2599
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
   907
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   908
#define HAVE_BOX
3420
0a31dc2fa8a0 _rl_accels.c: remove support for Python < 2.3
rgbecker
parents: 2965
diff changeset
   909
#ifdef HAVE_BOX
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   910
/*Box start**************/
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   911
typedef struct {
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   912
	PyObject_HEAD
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   913
	unsigned	is_box:1;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   914
	unsigned	is_glue:1;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   915
	unsigned	is_penalty:1;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   916
	unsigned	is_none:1;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   917
	double		width,stretch,shrink,penalty;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   918
	int			flagged;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   919
	char		character;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   920
	} BoxObject;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   921
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   922
static void BoxFree(BoxObject* self)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   923
{
3730
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
   924
	PyObject_Del(self);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   925
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   926
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   927
static int Box_set_int(char* name, int* pd, PyObject *value)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   928
{
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   929
	PyObject *v = PyNumber_Long(value);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   930
	if(!v) return -1;
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   931
	*pd = PyLong_AsLong(v);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   932
	Py_DECREF(v);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   933
	return 0;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   934
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   935
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   936
static int Box_set_double(char* name, double* pd, PyObject *value)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   937
{
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   938
	PyObject *v = PyNumber_Float(value);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   939
	if(!v) return -1;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   940
	*pd = PyFloat_AsDouble(v);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   941
	Py_DECREF(v);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   942
	return 0;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   943
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   944
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   945
static int Box_set_character(BoxObject *self, PyObject *value)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   946
{
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   947
	if(value==Py_None){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   948
		self->is_none = 1;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   949
		}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   950
	else {
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   951
		char *v = PyBytes_AsString(value);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   952
		if(!v) return -1;
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   953
		if(PyBytes_GET_SIZE(value)!=1){
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
   954
			PyErr_Format(PyExc_AttributeError,"Bad size %d('%s') for attribute character",PyBytes_GET_SIZE(value),v);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   955
			return -1;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   956
			}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   957
		self->character = v[0];
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   958
		self->is_none = 0;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   959
		}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   960
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   961
	return 0;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   962
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   963
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   964
static int Box_setattr(BoxObject *self, char *name, PyObject* value)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   965
{
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   966
	if(!strcmp(name,"width")) return Box_set_double(name,&self->width,value);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   967
	else if(!strcmp(name,"character")) return Box_set_character(self,value);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   968
	else if(!strcmp(name,"stretch")) return Box_set_double(name,&self->stretch,value);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   969
	else if(!strcmp(name,"shrink")) return Box_set_double(name,&self->shrink,value);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   970
	else if(!strcmp(name,"penalty")) return Box_set_double(name,&self->penalty,value);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   971
	else if(!strcmp(name,"flagged")) return Box_set_int(name,&self->flagged,value);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   972
	else if(
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   973
			!strcmp(name,"is_penalty") ||
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   974
			!strcmp(name,"is_box") ||
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   975
			!strcmp(name,"is_glue")
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   976
			) PyErr_Format(PyExc_AttributeError, "readonly attribute %s", name);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   977
	else PyErr_Format(PyExc_AttributeError, "no attribute %s", name);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   978
	return -1;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   979
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   980
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   981
static double _Glue_compute_width(BoxObject *self, double r)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   982
{
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   983
	if(self->is_glue) return self->width+r*(r<0?self->shrink:self->stretch);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   984
	return self->width;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   985
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   986
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   987
static PyObject* Glue_compute_width(BoxObject *self, PyObject *args)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   988
{
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   989
	double r;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   990
	if(!PyArg_ParseTuple(args, "d:compute_width", &r)) return NULL;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   991
	return PyFloat_FromDouble(_Glue_compute_width(self,r));
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   992
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   993
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   994
static struct PyMethodDef Box_methods[] = {
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   995
	{"compute_width", (PyCFunction)Glue_compute_width, METH_VARARGS|METH_KEYWORDS, "compute_width(r)"},
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   996
	{NULL, NULL}		/* sentinel */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   997
	};
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   998
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
   999
static PyObject* Box_get_character(unsigned is_none, char c)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1000
{
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
  1001
	if(!is_none) return PyBytes_FromStringAndSize(&c,1);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1002
	else {
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1003
		Py_INCREF(Py_None);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1004
		return Py_None;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1005
		}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1006
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1007
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1008
static PyObject* Box_getattr(BoxObject *self, char *name)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1009
{
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1010
	if(!strcmp(name,"width")) return PyFloat_FromDouble(self->width);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1011
	else if(!strcmp(name,"character")) return Box_get_character(self->is_none,self->character);
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
  1012
	else if(!strcmp(name,"is_box")) return PyBool_FromLong(self->is_box);
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
  1013
	else if(!strcmp(name,"is_glue")) return PyBool_FromLong(self->is_glue);
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
  1014
	else if(!strcmp(name,"is_penalty")) return PyBool_FromLong(self->is_penalty);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1015
	else if(!strcmp(name,"stretch")) return PyFloat_FromDouble(self->stretch);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1016
	else if(!strcmp(name,"shrink")) return PyFloat_FromDouble(self->shrink);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1017
	else if(!strcmp(name,"penalty")) return PyFloat_FromDouble(self->penalty);
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
  1018
	else if(!strcmp(name,"flagged")) return PyBool_FromLong(self->flagged);
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
  1019
	return PyObject_GetAttrString((PyObject *)self, name);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1020
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1021
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1022
static PyTypeObject BoxType = {
3730
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1023
	PyVarObject_HEAD_INIT(NULL,0)
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1024
	"_rl_accel.Box",				/*tp_name*/
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1025
	sizeof(BoxObject),				/*tp_basicsize*/
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1026
	0,								/*tp_itemsize*/
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1027
	/* methods */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1028
	(destructor)BoxFree,			/*tp_dealloc*/
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1029
	(printfunc)0,					/*tp_print*/
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1030
	(getattrfunc)Box_getattr,		/*tp_getattr*/
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1031
	(setattrfunc)Box_setattr,		/*tp_setattr*/
3730
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1032
	0,								/*tp_reserved*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1033
	0,								/*tp_repr*/
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1034
	0,								/*tp_as_number*/
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1035
	0,								/*tp_as_sequence*/
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1036
	0,								/*tp_as_mapping*/
3730
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1037
	0,								/*tp_hash*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1038
	0,								/*tp_call*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1039
	0,								/*tp_str*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1040
	0,	 							/*tp_getattro*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1041
	0,								/*tp_setattro*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1042
	0,								/*tp_as_buffer*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1043
	Py_TPFLAGS_DEFAULT,				/*tp_flags*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1044
	"Box instance, see doc string for details.", /*tp_doc*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1045
	0,								/*tp_traverse*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1046
	0,								/*tp_clear*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1047
	0,								/*tp_richcompare*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1048
	0,								/*tp_weaklistoffset*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1049
	0,								/*tp_iter*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1050
	0,								/*tp_iternext*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1051
	Box_methods,					/*tp_methods*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1052
	0,								/*tp_members*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1053
	0,								/*tp_getset*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1054
	0,								/*tp_base*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1055
	0,								/*tp_dict*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1056
	0,								/*tp_descr_get*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1057
	0,								/*tp_descr_set*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1058
	0,								/*tp_dictoffset*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1059
	0,								/*tp_init*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1060
	0,								/*tp_alloc*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1061
	0,								/*tp_new*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1062
	0,								/*tp_free*/
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1063
	0,								/*tp_is_gc*/
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1064
};
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1065
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1066
static BoxObject* Box(PyObject* module, PyObject* args, PyObject* kw)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1067
{
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1068
	BoxObject* self;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1069
	char	*kwlist[] = {"width","character",NULL};
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1070
	PyObject	*pC=NULL;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1071
	double		w;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1072
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1073
	if(!PyArg_ParseTupleAndKeywords(args,kw,"d|O:Box",kwlist,&w,&pC)) return NULL;
3993
f807a6e50a63 _rl_accel.c: PyObject_NEW-->PyObject_New (contributed by Matthias Klose)
robin
parents: 3980
diff changeset
  1074
	if(!(self = PyObject_New(BoxObject, &BoxType))) return NULL;
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1075
	self->shrink = self->stretch = self->penalty = (double)(self->is_glue = self->is_penalty = self->flagged = 0);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1076
	self->is_box = 1;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1077
	self->width = w;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1078
	if(Box_set_character(self, pC ? pC : Py_None)){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1079
		BoxFree(self);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1080
		return NULL;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1081
		}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1082
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1083
	return self;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1084
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1085
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1086
static BoxObject* Glue(PyObject* module, PyObject* args, PyObject* kw)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1087
{
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1088
	BoxObject* self;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1089
	char	*kwlist[] = {"width","stretch","shrink",NULL};
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1090
	double		width,stretch,shrink;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1091
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1092
	if(!PyArg_ParseTupleAndKeywords(args,kw,"ddd:Glue",kwlist,&width,&stretch,&shrink)) return NULL;
3993
f807a6e50a63 _rl_accel.c: PyObject_NEW-->PyObject_New (contributed by Matthias Klose)
robin
parents: 3980
diff changeset
  1093
	if(!(self = PyObject_New(BoxObject, &BoxType))) return NULL;
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1094
	self->penalty = (double)(self->is_box = self->is_penalty = self->flagged = 0);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1095
	self->is_glue = self->is_none = 1;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1096
	self->width = width;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1097
	self->stretch = stretch;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1098
	self->shrink = shrink;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1099
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1100
	return self;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1101
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1102
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1103
static BoxObject* Penalty(PyObject* module, PyObject* args, PyObject* kw)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1104
{
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1105
	BoxObject* self;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1106
	char	*kwlist[] = {"width","penalty","flagged",NULL};
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1107
	double	width,penalty;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1108
	int		flagged = 0;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1109
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1110
	if(!PyArg_ParseTupleAndKeywords(args,kw,"dd|i:Penalty",kwlist,&width,&penalty,&flagged)) return NULL;
3993
f807a6e50a63 _rl_accel.c: PyObject_NEW-->PyObject_New (contributed by Matthias Klose)
robin
parents: 3980
diff changeset
  1111
	if(!(self = PyObject_New(BoxObject, &BoxType))) return NULL;
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1112
	self->shrink = self->stretch = (double)(self->is_box = self->is_glue = 0);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1113
	self->is_penalty = self->is_none = 1;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1114
	self->width = width;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1115
	self->penalty = penalty;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1116
	self->flagged = flagged;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1117
	return self;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1118
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1119
/*Box end****************/
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1120
/* BoxList -- a list subtype */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1121
typedef struct {
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1122
	PyListObject list;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1123
	int state;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1124
	} BoxListobject;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1125
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1126
static PyObject *BoxList_getstate(BoxListobject *self, PyObject *args)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1127
{
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1128
	if (!PyArg_ParseTuple(args, ":getstate")) return NULL;
3730
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1129
	return PyLong_FromLong(self->state);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1130
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1131
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1132
static PyObject *BoxList_setstate(BoxListobject *self, PyObject *args)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1133
{
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1134
	int state;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1135
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1136
	if (!PyArg_ParseTuple(args, "i:setstate", &state))
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1137
		return NULL;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1138
	self->state = state;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1139
	Py_INCREF(Py_None);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1140
	return Py_None;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1141
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1142
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1143
static PyObject *BoxList_specialmeth(PyObject *self, PyObject *args, PyObject *kw)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1144
{
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1145
	PyObject *result = PyTuple_New(3);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1146
	if(result!=NULL){
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1147
		if(self==NULL) self = Py_None;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1148
		if(kw==NULL) kw = Py_None;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1149
		Py_INCREF(self);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1150
		PyTuple_SET_ITEM(result, 0, self);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1151
		Py_INCREF(args);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1152
		PyTuple_SET_ITEM(result, 1, args);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1153
		Py_INCREF(kw);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1154
		PyTuple_SET_ITEM(result, 2, kw);
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1155
		}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1156
	return result;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1157
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1158
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1159
static PyMethodDef BoxList_methods[] = {
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1160
	{"getstate", (PyCFunction)BoxList_getstate, METH_VARARGS, "getstate() -> state"},
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1161
	{"setstate", (PyCFunction)BoxList_setstate, METH_VARARGS, "setstate(state)"},
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1162
	/* These entries differ only in the flags; they are used by the tests in test.test_descr. */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1163
	{"classmeth", (PyCFunction)BoxList_specialmeth, METH_VARARGS | METH_KEYWORDS | METH_CLASS, "classmeth(*args, **kw)"},
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1164
	{"staticmeth", (PyCFunction)BoxList_specialmeth, METH_VARARGS | METH_KEYWORDS | METH_STATIC, "staticmeth(*args, **kw)"},
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1165
	{NULL,	NULL},
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1166
	};
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1167
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1168
static PyTypeObject BoxList_type;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1169
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1170
static int BoxList_init(BoxListobject *self, PyObject *args, PyObject *kwds)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1171
{
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1172
	if(PyList_Type.tp_init((PyObject *)self, args, kwds)<0) return -1;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1173
	self->state = 0;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1174
	return 0;
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1175
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1176
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1177
static PyObject *BoxList_state_get(BoxListobject *self)
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1178
{
3730
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1179
	return PyLong_FromLong(self->state);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1180
}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1181
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1182
static PyGetSetDef BoxList_getsets[] = {
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1183
	{"state", (getter)BoxList_state_get, NULL, PyDoc_STR("an int variable for demonstration purposes")},
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1184
	{0}
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1185
	};
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1186
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1187
static PyTypeObject BoxList_type = {
3730
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1188
    PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1189
	"_rl_accel.BoxList",
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1190
	sizeof(BoxListobject),
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1191
	0,
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1192
	0,					/* tp_dealloc */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1193
	0,					/* tp_print */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1194
	0,					/* tp_getattr */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1195
	0,					/* tp_setattr */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1196
	0,					/* tp_compare */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1197
	0,					/* tp_repr */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1198
	0,					/* tp_as_number */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1199
	0,					/* tp_as_sequence */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1200
	0,					/* tp_as_mapping */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1201
	0,					/* tp_hash */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1202
	0,					/* tp_call */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1203
	0,					/* tp_str */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1204
	0,					/* tp_getattro */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1205
	0,					/* tp_setattro */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1206
	0,					/* tp_as_buffer */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1207
	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1208
	0,					/* tp_doc */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1209
	0,					/* tp_traverse */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1210
	0,					/* tp_clear */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1211
	0,					/* tp_richcompare */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1212
	0,					/* tp_weaklistoffset */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1213
	0,					/* tp_iter */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1214
	0,					/* tp_iternext */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1215
	BoxList_methods,			/* tp_methods */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1216
	0,					/* tp_members */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1217
	BoxList_getsets,			/* tp_getset */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1218
	DEFERRED_ADDRESS(&PyList_Type),		/* tp_base */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1219
	0,					/* tp_dict */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1220
	0,					/* tp_descr_get */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1221
	0,					/* tp_descr_set */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1222
	0,					/* tp_dictoffset */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1223
	(initproc)BoxList_init,		/* tp_init */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1224
	0,					/* tp_alloc */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1225
	0,					/* tp_new */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1226
};
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1227
#endif
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1228
3777
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1229
#ifdef	HAVE_BOX
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1230
#define _BOX__DOC__ \
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1231
	"\tBox(width,character=None) creates a Knuth character Box with the specified width.\n" \
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1232
	"\tGlue(width,stretch,shrink) creates a Knuth glue Box with the specified width, stretch and shrink.\n" \
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1233
	"\tPenalty(width,penalty,flagged=0) creates a Knuth penalty Box with the specified width and penalty.\n" \
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1234
	"\tBoxList() creates a knuth box list.\n"
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1235
#endif
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1236
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1237
PyDoc_STRVAR(__DOC__,
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1238
"_rl_accel contains various accelerated utilities\n\
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1239
\n\
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1240
\tescapePDF makes a string safe for PDF\n\
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1241
\n\
3778
1c9196ca9795 exported name changes
robin
parents: 3777
diff changeset
  1242
\tasciiBase85Encode does what is says\n\
1c9196ca9795 exported name changes
robin
parents: 3777
diff changeset
  1243
\tasciiBase85Decode does what is says\n\
3777
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1244
\n\
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1245
\tfp_str converts numeric arguments to a single blank separated string\n\
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1246
\tcalcChecksum calculate checksums for TTFs (legacy)\n\
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1247
\tadd32 32 bit unsigned addition (legacy)\n\
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1248
\thex32 32 bit unsigned to 0X8.8X string\n\
3778
1c9196ca9795 exported name changes
robin
parents: 3777
diff changeset
  1249
\tinstanceStringWidthT1 version2 Font instance stringWidth\n\
1c9196ca9795 exported name changes
robin
parents: 3777
diff changeset
  1250
\tinstanceStringWidthTTF version2 TTFont instance stringWidth\n\
3777
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1251
\tunicode2T1 version2 pdfmetrics.unicode2T1\n"
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1252
_BOX__DOC__
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1253
);
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1254
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1255
static struct PyMethodDef _methods[] = {
4002
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
  1256
	{"asciiBase85Encode", _a85_encode, METH_VARARGS, "asciiBase85Encode(\".....\") return encoded " STRNAME},
4bf4b598196e _rl_accel.c & rl_accel.py: fix aascii85 encode decode to do the 'right' thing
robin
parents: 3993
diff changeset
  1257
	{"asciiBase85Decode", _a85_decode, METH_VARARGS, "asciiBase85Decode(\".....\") return decoded " BYTESNAME},
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1258
	{"escapePDF", escapePDF, METH_VARARGS, "escapePDF(s) return PDF safed string"},
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1259
	{"fp_str", _fp_str, METH_VARARGS, "fp_str(a0, a1,...) convert numerics to blank separated string"},
3778
1c9196ca9795 exported name changes
robin
parents: 3777
diff changeset
  1260
	{"sameFrag", sameFrag, 1, "sameFrag(f,g) return 1 if fragments have same style"},
3728
8559eca73c9c _rl_accel changes
robin
parents: 3727
diff changeset
  1261
	{"calcChecksum", ttfonts_calcChecksum, METH_VARARGS, "calcChecksum(string) calculate checksums for TTFs (returns long)"},
3730
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1262
	{"add32", ttfonts_add32, METH_VARARGS, "add32(x,y)  32 bit unsigned x+y (returns long)"},
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1263
	{"hex32", hex32, METH_VARARGS, "hex32(x)  32 bit unsigned-->0X8.8X string"},
2599
0f5d38a308e0 _rl_accel.c: added unicode2T1
rgbecker
parents: 2483
diff changeset
  1264
	{"unicode2T1", (PyCFunction)unicode2T1, METH_VARARGS|METH_KEYWORDS, "return a list of (font,string) pairs representing the unicode text"},
3778
1c9196ca9795 exported name changes
robin
parents: 3777
diff changeset
  1265
	{"instanceStringWidthT1", (PyCFunction)instanceStringWidthT1, METH_VARARGS|METH_KEYWORDS, "Font.stringWidth(self,text,fontName,fontSize,encoding='utf8') --> width"},
1c9196ca9795 exported name changes
robin
parents: 3777
diff changeset
  1266
	{"instanceStringWidthTTF", (PyCFunction)instanceStringWidthTTF, METH_VARARGS|METH_KEYWORDS, "TTFont.stringWidth(self,text,fontName,fontSize,encoding='utf8') --> width"},
2390
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1267
#ifdef	HAVE_BOX
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1268
	{"Box",	(PyCFunction)Box,	METH_VARARGS|METH_KEYWORDS, "Box(width,character=None) create a Knuth Box instance"},
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1269
	{"Glue", (PyCFunction)Glue,	METH_VARARGS|METH_KEYWORDS, "Glue(width,stretch,shrink) create a Knuth Glue instance"},
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1270
	{"Penalty", (PyCFunction)Penalty,	METH_VARARGS|METH_KEYWORDS, "Penalty(width,penalty,flagged=0) create a Knuth Penalty instance"},
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1271
#endif
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1272
	{NULL,		NULL}		/* sentinel */
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1273
	};
d46ae0ab7698 reportlab/lib: moved _rl_accel and friends to rl_addons/rl_accel
rgbecker
parents:
diff changeset
  1274
4246
6fbc9729b120 remove excess state and fix refcount breakage (contribution by Mark De Wit <mark.dewit@iesve.com>) _rl_accel-->0.71
robin
parents: 4002
diff changeset
  1275
/*Initialization function for the module*/
3727
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
  1276
#ifdef isPy3
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
  1277
static struct PyModuleDef moduledef = {
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
  1278
	PyModuleDef_HEAD_INIT,
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
  1279
	"_rl_accel",
3777
99bd303ec516 _rl_accel.c now compiles on both Python-2.7 VC9 & Python-3.3 VC10
robin
parents: 3765
diff changeset
  1280
	__DOC__,
3727
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
  1281
	sizeof(struct module_state),
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
  1282
	_methods,
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
  1283
	NULL,
4246
6fbc9729b120 remove excess state and fix refcount breakage (contribution by Mark De Wit <mark.dewit@iesve.com>) _rl_accel-->0.71
robin
parents: 4002
diff changeset
  1284
	NULL,
6fbc9729b120 remove excess state and fix refcount breakage (contribution by Mark De Wit <mark.dewit@iesve.com>) _rl_accel-->0.71
robin
parents: 4002
diff changeset
  1285
	NULL,
3727
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
  1286
	NULL
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
  1287
	};
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
  1288
3730
690aaa390f45 latest attempt at _rl_accel.c
rptlab
parents: 3728
diff changeset
  1289
PyMODINIT_FUNC PyInit__rl_accel(void)
3727
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477
diff changeset
  1290
#else
67e69a84138b changes to bring into line with new Python 3.3.0 universe
robin
parents: 3477