src/rl_addons/renderPM/_renderPM.c
author robin
Mon, 12 Sep 2022 09:33:45 +0100
changeset 4737 e39e4741759a
parent 4668 f8d6dc8f07fc
child 4740 5e0221f70afc
permissions -rw-r--r--
nano bugfix in rl_addons/renderPM/_renderPM.c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4508
5f79dd4e0cc8 add some fixes inspired by Marius Gedminas as a partial fix of bb issue #174
robin <robin@reportlab.com>
parents: 4458
diff changeset
     1
#define PY_SSIZE_T_CLEAN
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
     2
#include "Python.h"
3753
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
     3
994
5d42ea5093e1 Niki Spahiev's PyMem_New patch for 1.5.2
rgbecker
parents: 898
diff changeset
     4
#ifndef PyMem_New
5d42ea5093e1 Niki Spahiev's PyMem_New patch for 1.5.2
rgbecker
parents: 898
diff changeset
     5
	/*Niki Spahiev <niki@vintech.bg> suggests this is required for 1.5.2*/
5d42ea5093e1 Niki Spahiev's PyMem_New patch for 1.5.2
rgbecker
parents: 898
diff changeset
     6
#	define PyMem_New(type, n) ( (type *) PyMem_Malloc((n) * sizeof(type)) )
5d42ea5093e1 Niki Spahiev's PyMem_New patch for 1.5.2
rgbecker
parents: 898
diff changeset
     7
#endif
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
     8
#include <string.h>
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
     9
#include "libart_lgpl/libart.h"
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    10
#include "gt1/gt1-parset1.h"
3753
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
    11
#include "gt1/gt1-misc.h"
4640
626937a80b64 cosmetic changes and add gstate setattr for fontSize
robin
parents: 4635
diff changeset
    12
#define FILL_UNSET -1
4306
8ffb2ffc283b support for Path autoclose & fillMode; version --> 3.3.29
robin
parents: 4303
diff changeset
    13
#define FILL_EVEN_ODD 0
8ffb2ffc283b support for Path autoclose & fillMode; version --> 3.3.29
robin
parents: 4303
diff changeset
    14
#define FILL_NON_ZERO 1
1008
09e39778e2b5 changes to make it compile under MacOS:
jvr
parents: 994
diff changeset
    15
4621
ac04f5205b5d attempt to fix OSX builds after successful test build
robin
parents: 4620
diff changeset
    16
#if defined(macintosh)
1008
09e39778e2b5 changes to make it compile under MacOS:
jvr
parents: 994
diff changeset
    17
#	include <extras.h>
09e39778e2b5 changes to make it compile under MacOS:
jvr
parents: 994
diff changeset
    18
#	define strdup _strdup
09e39778e2b5 changes to make it compile under MacOS:
jvr
parents: 994
diff changeset
    19
#endif
09e39778e2b5 changes to make it compile under MacOS:
jvr
parents: 994
diff changeset
    20
09e39778e2b5 changes to make it compile under MacOS:
jvr
parents: 994
diff changeset
    21
4737
e39e4741759a nano bugfix in rl_addons/renderPM/_renderPM.c
robin
parents: 4668
diff changeset
    22
#define VERSION "4.02"
3753
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
    23
#define MODULENAME "_renderPM"
4668
f8d6dc8f07fc remove support for 2.7; require >=3.6; version-->3.6.0
robin
parents: 4640
diff changeset
    24
#define PyInt_FromLong	PyLong_FromLong
f8d6dc8f07fc remove support for 2.7; require >=3.6; version-->3.6.0
robin
parents: 4640
diff changeset
    25
#define staticforward static
f8d6dc8f07fc remove support for 2.7; require >=3.6; version-->3.6.0
robin
parents: 4640
diff changeset
    26
#define statichere static
3753
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
    27
PyObject *RLPy_FindMethod(PyMethodDef *ml, PyObject *self, const char* name){
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
    28
	for(;ml->ml_name!=NULL;ml++)
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
    29
		if(name[0]==ml->ml_name[0] && strcmp(name+1,ml->ml_name+1)==0) return PyCFunction_New(ml, self);
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
    30
	return NULL;
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
    31
	}
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
    32
#define Py_FindMethod RLPy_FindMethod
4601
f3e622b58a0c use a STRINGIFY macro in _renderPM.c; remove excess quotes in setup.py
robin
parents: 4593
diff changeset
    33
#define __STR(x) #x
f3e622b58a0c use a STRINGIFY macro in _renderPM.c; remove excess quotes in setup.py
robin
parents: 4593
diff changeset
    34
#define STRINGIFY(x) __STR(x)
1674
529dd4d50687 Sync with Gnome libart_lgpl 2.3.10
rgbecker
parents: 1326
diff changeset
    35
#ifndef LIBART_VERSION
4601
f3e622b58a0c use a STRINGIFY macro in _renderPM.c; remove excess quotes in setup.py
robin
parents: 4593
diff changeset
    36
#	define LIBART_VERSION ?.?.?
1674
529dd4d50687 Sync with Gnome libart_lgpl 2.3.10
rgbecker
parents: 1326
diff changeset
    37
#endif
3775
85dda3d585fa _renderPM.c fix macro for MSVC9
robin
parents: 3767
diff changeset
    38
#ifdef	RENDERPM_FT
4604
e286458cd0c7 fix memory leak in _renderPM.c
robin
parents: 4601
diff changeset
    39
#	define _FT_DOC "    _renderPM.ft_get_face(fontName) --> ft_face instance\n"
3775
85dda3d585fa _renderPM.c fix macro for MSVC9
robin
parents: 3767
diff changeset
    40
#else
85dda3d585fa _renderPM.c fix macro for MSVC9
robin
parents: 3767
diff changeset
    41
#	define _FT_DOC ""
85dda3d585fa _renderPM.c fix macro for MSVC9
robin
parents: 3767
diff changeset
    42
#endif
4604
e286458cd0c7 fix memory leak in _renderPM.c
robin
parents: 4601
diff changeset
    43
#ifdef MEMORY_DEBUG
e286458cd0c7 fix memory leak in _renderPM.c
robin
parents: 4601
diff changeset
    44
#	define _MDBG_DOC "    _renderPM.mtrace(int) start or stop the malloc tracing\n"
e286458cd0c7 fix memory leak in _renderPM.c
robin
parents: 4601
diff changeset
    45
#else
e286458cd0c7 fix memory leak in _renderPM.c
robin
parents: 4601
diff changeset
    46
#	define _MDBG_DOC ""
e286458cd0c7 fix memory leak in _renderPM.c
robin
parents: 4601
diff changeset
    47
#endif
3753
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
    48
PyDoc_STRVAR(__DOC__,
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    49
"Helper extension module for renderPM.\n\
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    50
\n\
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    51
Interface summary:\n\
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    52
\n\
4604
e286458cd0c7 fix memory leak in _renderPM.c
robin
parents: 4601
diff changeset
    53
    from reportlan.graphics import _renderPM\n\
e286458cd0c7 fix memory leak in _renderPM.c
robin
parents: 4601
diff changeset
    54
    _renderPM.gstate(width,height[,depth=3,bg=0xffffff]) create an \n\
e286458cd0c7 fix memory leak in _renderPM.c
robin
parents: 4601
diff changeset
    55
        initialised graphics state\n\
e286458cd0c7 fix memory leak in _renderPM.c
robin
parents: 4601
diff changeset
    56
    _renderPM.makeT1Font(fontName,pfbPath,names[,reader]) make a T1 font\n\
e286458cd0c7 fix memory leak in _renderPM.c
robin
parents: 4601
diff changeset
    57
    _renderPM.delCache() delete all T1 font info\n\
e286458cd0c7 fix memory leak in _renderPM.c
robin
parents: 4601
diff changeset
    58
    _renderPM.pil2pict(cols,rows,datastr,palette) return PICT version of\n\
e286458cd0c7 fix memory leak in _renderPM.c
robin
parents: 4601
diff changeset
    59
        im as bytes\n"
3775
85dda3d585fa _renderPM.c fix macro for MSVC9
robin
parents: 3767
diff changeset
    60
_FT_DOC
4604
e286458cd0c7 fix memory leak in _renderPM.c
robin
parents: 4601
diff changeset
    61
_MDBG_DOC
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
    62
"\n\
4604
e286458cd0c7 fix memory leak in _renderPM.c
robin
parents: 4601
diff changeset
    63
    _renderPM._libart_version base library version string\n\
e286458cd0c7 fix memory leak in _renderPM.c
robin
parents: 4601
diff changeset
    64
    _renderPM._version module version string ie " VERSION "\n\
3753
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
    65
");
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    66
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
    67
#if PY_VERSION_HEX < 0x01060000
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
    68
#	define PyObject_DEL(op) PyMem_DEL((op))
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
    69
#endif
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
    70
4593
765c7f6801b5 fix barchart axis crossing, nano eedit to _renderPM.c; version-->3.5.45
robin
parents: 4508
diff changeset
    71
#define VECSP 0.25
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    72
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    73
typedef struct {
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    74
  int format;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    75
  art_u8 * buf;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    76
  int width;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    77
  int height;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    78
  int nchan;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    79
  int rowstride;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    80
} pixBufT;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    81
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    82
typedef	struct {
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    83
		size_t	width;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    84
		size_t	height;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    85
		size_t	stride;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    86
		art_u8	*buf;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    87
		} gstateColorX;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
    88
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
    89
#ifdef	RENDERPM_FT
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
    90
static	PyObject* parse_utf8(PyObject* self, PyObject* args)
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
    91
{
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
    92
	char		*c, *msg;
4508
5f79dd4e0cc8 add some fixes inspired by Marius Gedminas as a partial fix of bb issue #174
robin <robin@reportlab.com>
parents: 4458
diff changeset
    93
	Py_ssize_t	n;
5f79dd4e0cc8 add some fixes inspired by Marius Gedminas as a partial fix of bb issue #174
robin <robin@reportlab.com>
parents: 4458
diff changeset
    94
	int			i;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
    95
	unsigned	first, second, third;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
    96
	PyObject	*r;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
    97
    if(!PyArg_ParseTuple(args, "t#:parse_utf8", &c, &n)) return NULL;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
    98
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
    99
	i = 0;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   100
	r = PyList_New(0);
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   101
	while(i<n){
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   102
		first = c[i++];
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   103
		if(first<0x80) PyList_Append(r, PyInt_FromLong(first));
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   104
		else if(first<0xc0){
3475
88247310430c _renderPM.c: change label ERR to RL_ERROR_EXIT fixes breakage in solaris; contributed by Alex Buck
rgbecker
parents: 3386
diff changeset
   105
E0:			msg = "Invalid UTF-8 String";
88247310430c _renderPM.c: change label ERR to RL_ERROR_EXIT fixes breakage in solaris; contributed by Alex Buck
rgbecker
parents: 3386
diff changeset
   106
			goto RL_ERROR_EXIT;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   107
			}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   108
		else if(first<0xE0){
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   109
			second = c[i++];
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   110
			if(second<0x80||second>=0xc0) goto E0;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   111
			PyList_Append(r, PyInt_FromLong((((first&0x1f)<<6)|(second&0x3f))));
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   112
			}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   113
		else if(first<0xE0){
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   114
			second = c[i++];
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   115
			third = c[i++];
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   116
			if(second<0x80 || second>=0xC0 || third<0x80 || third>=0xC0) goto E0;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   117
			PyList_Append(r, PyInt_FromLong((((first&0x0f)<<12)|((second&0x3f)<<6)|(third&0x3f))));
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   118
			}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   119
		else{
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   120
			msg = "UTF-8 characters outside 16-bit range not supported";
3475
88247310430c _renderPM.c: change label ERR to RL_ERROR_EXIT fixes breakage in solaris; contributed by Alex Buck
rgbecker
parents: 3386
diff changeset
   121
			goto RL_ERROR_EXIT;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   122
			}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   123
		}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   124
	return r;
3475
88247310430c _renderPM.c: change label ERR to RL_ERROR_EXIT fixes breakage in solaris; contributed by Alex Buck
rgbecker
parents: 3386
diff changeset
   125
RL_ERROR_EXIT:
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   126
    Py_DECREF(r);
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   127
	PyErr_SetString(PyExc_ValueError,msg);
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   128
    Py_INCREF(Py_None);
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   129
	return Py_None;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   130
}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   131
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   132
PyObject*	_pdfmetrics__fonts=0;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   133
static PyObject *_get_pdfmetrics__fonts(void){
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   134
	if(!_pdfmetrics__fonts){
2111
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   135
		PyObject *mod=PyImport_ImportModule("reportlab.pdfbase.pdfmetrics");
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   136
		if(mod){
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   137
			_pdfmetrics__fonts = PyObject_GetAttrString(mod,"_fonts");
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   138
			Py_DECREF(mod);
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   139
			}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   140
		}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   141
	return _pdfmetrics__fonts;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   142
	}
2560
a9779a524320 renderPM: minor fix for standardc usrlocal freetype2 stuff
rgbecker
parents: 2559
diff changeset
   143
#include <ft2build.h>
2559
c6b086e81923 rl_addons: changes for building in freeBSD environment
rgbecker
parents: 2510
diff changeset
   144
#include FT_FREETYPE_H
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   145
static FT_Library ft_library=0;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   146
typedef struct {
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   147
    PyObject_HEAD
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   148
    FT_Face face;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   149
	} py_FT_FontObject;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   150
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   151
staticforward PyTypeObject py_FT_Font_Type;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   152
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   153
/* round a 26.6 pixel coordinate to the nearest larger integer */
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   154
#define PIXEL(x) ((((x)+63) & -64)>>6)
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   155
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   156
static py_FT_FontObject *_get_ft_face(char *fontName)
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   157
{
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   158
    int				error = 1;
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   159
	PyObject		*_fonts=_get_pdfmetrics__fonts();
2111
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   160
	PyObject		*font, *face, *_data;
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   161
	py_FT_FontObject *ft_face;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   162
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   163
	if(!_fonts) return NULL;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   164
	font = PyDict_GetItemString(_fonts,fontName);
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   165
	if(!font) return NULL;
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   166
	ft_face = (py_FT_FontObject*)PyObject_GetAttrString(font,"_ft_face");
2111
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   167
	if(ft_face) return ft_face;
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   168
	PyErr_Clear();
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   169
	if(!ft_library){
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   170
		if(FT_Init_FreeType(&ft_library)){
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   171
			PyErr_SetString(PyExc_IOError,"cannot initialize FreeType library");
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   172
			goto RET;
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   173
			}
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   174
		}
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   175
2111
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   176
	ft_face = PyObject_NEW(py_FT_FontObject, &py_FT_Font_Type);
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   177
	if(!ft_face){
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   178
		PyErr_Format(PyExc_MemoryError, "Cannot allocate ft_face for TTFont %s", fontName);
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   179
		goto RET;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   180
		}
4737
e39e4741759a nano bugfix in rl_addons/renderPM/_renderPM.c
robin
parents: 4668
diff changeset
   181
	ft_face->face = NULL;
2111
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   182
	face = PyObject_GetAttrString(font,"face");
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   183
	if(!face) goto RET;
2122
59a3555b0acb Fix unset field change to _ttf_data
rgbecker
parents: 2114
diff changeset
   184
	_data = PyObject_GetAttrString(face,"_ttf_data");
2111
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   185
	Py_DECREF(face);
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   186
	if(!_data) goto RET;
4508
5f79dd4e0cc8 add some fixes inspired by Marius Gedminas as a partial fix of bb issue #174
robin <robin@reportlab.com>
parents: 4458
diff changeset
   187
	error = FT_New_Memory_Face(ft_library, (unsigned char *)PyBytes_AsString(_data), (FT_Long)PyBytes_GET_SIZE(_data), 0, &ft_face->face);
2111
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   188
	Py_DECREF(_data);
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   189
	if(error){
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   190
		PyErr_Format(PyExc_IOError, "FT_New_Memory_Face(%s) Failed!", fontName);
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   191
		goto RET;
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   192
		}
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   193
	PyObject_SetAttrString(font,"_ft_face",(PyObject*)ft_face);
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   194
RET:if(error && ft_face){
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   195
		Py_DECREF(ft_face);
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   196
		ft_face  = NULL;
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   197
		}
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   198
    return ft_face;
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   199
}
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   200
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   201
static FT_Face _ft_get_face(char *fontName)
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   202
{
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   203
	py_FT_FontObject	*ft_face = _get_ft_face(fontName);
2110
cca387467c50 Fixed memory family problems
rgbecker
parents: 2108
diff changeset
   204
	if(ft_face){
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   205
		FT_Face	face = ft_face->face;
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   206
		Py_DECREF(ft_face);
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   207
    	return face;
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   208
		}
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   209
	return NULL;
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   210
}
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   211
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   212
static	PyObject*	ft_get_face(PyObject* self, PyObject* args)
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   213
{
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   214
	char* fontName;
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   215
	if(!PyArg_ParseTuple(args,"s:ft_get_face",&fontName)) return NULL;
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   216
	return (PyObject*)_get_ft_face(fontName);
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   217
}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   218
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   219
static void py_FT_font_dealloc(py_FT_FontObject* self)
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   220
{
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   221
    if(self->face) FT_Done_Face(self->face);
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   222
    PyObject_DEL(self);
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   223
}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   224
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   225
static PyObject*  py_FT_font_getattr(py_FT_FontObject* self, char* name)
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   226
{
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   227
    /* attributes */
3753
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
   228
    if (!strcmp(name, "family")) return PyUnicode_FromString(self->face->family_name);
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
   229
    if (!strcmp(name, "style")) return PyUnicode_FromString(self->face->style_name);
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   230
    if (!strcmp(name, "ascent")) return PyInt_FromLong(PIXEL(self->face->size->metrics.ascender));
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   231
    if (!strcmp(name, "descent")) return PyInt_FromLong(-PIXEL(self->face->size->metrics.descender));
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   232
    if (!strcmp(name, "num_glyphs")) return PyInt_FromLong(self->face->num_glyphs);
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   233
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   234
    PyErr_SetString(PyExc_AttributeError, name);
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   235
    return NULL;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   236
}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   237
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   238
statichere PyTypeObject py_FT_Font_Type = {
3753
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
   239
    PyVarObject_HEAD_INIT(NULL,0)
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
   240
    "FT_Font", sizeof(py_FT_FontObject), 0,
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   241
    /* methods */
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   242
    (destructor)py_FT_font_dealloc, /* tp_dealloc */
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   243
    0, /* tp_print */
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   244
    (getattrfunc)py_FT_font_getattr, /* tp_getattr */
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   245
	};
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   246
#endif /*ifdef	RENDERPM_FT*/
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   247
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   248
static pixBufT* pixBufAlloc(int w, int h, int nchan, gstateColorX bg)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   249
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   250
	pixBufT* p = PyMem_Malloc(sizeof(pixBufT));
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   251
	if(p){
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   252
		size_t	n;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   253
		p->format = 0; /* RGB */
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   254
		p->buf = PyMem_Malloc(n=w*h*nchan); /* start with white background by default */
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   255
		if(p->buf){
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   256
			/*initialise the pixmap pixels*/
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   257
			art_u8	*b, *lim = p->buf+n;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   258
			size_t	stride = w*nchan, i;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   259
			p->width = w;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   260
			p->height = h;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   261
			p->nchan = nchan;
4508
5f79dd4e0cc8 add some fixes inspired by Marius Gedminas as a partial fix of bb issue #174
robin <robin@reportlab.com>
parents: 4458
diff changeset
   262
			p->rowstride = (int)stride;
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   263
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   264
			/*set up the background*/
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   265
			if(bg.stride==0){	/*simple color case*/
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   266
				art_u32	bgv = (bg.buf[0]<<16) | (bg.buf[1]<<8) | bg.buf[2];
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   267
				for(i=0;i<(size_t)nchan;i++){
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   268
					art_u8 	c= (bgv>>(8*(nchan-i-1)))&0xff;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   269
					b = p->buf+i;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   270
					while(b<lim){
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   271
						*b = c;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   272
						b += nchan;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   273
						}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   274
					}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   275
				}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   276
			else{	/*image case*/
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   277
				size_t	j = 0;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   278
				art_u8	*r = bg.buf;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   279
				b = p->buf;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   280
				i = 0;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   281
				while(b<lim){
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   282
					*b++ = r[j++ % bg.stride];
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   283
					if(j==stride){
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   284
						r += bg.stride;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   285
						j = 0;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   286
						i++;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   287
						if(i==bg.height) r = bg.buf;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   288
						}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   289
					}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   290
				}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   291
			}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   292
		else {
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   293
			PyMem_Free(p);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   294
			p = NULL;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   295
			}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   296
		}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   297
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   298
	return p;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   299
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   300
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   301
static void pixBufFree(pixBufT** pp)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   302
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   303
	pixBufT*	p = *pp;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   304
	if(p){
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   305
		PyMem_Free(p->buf);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   306
		PyMem_Free(p);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   307
		*pp = 0;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   308
		}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   309
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   310
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   311
typedef	double	A2DMX[6];		/*Affine transforms*/
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   312
typedef	struct {
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   313
		art_u32	value;				/*the color value*/
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   314
		int		valid;				/*if it's valid*/
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   315
		} gstateColor;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   316
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   317
typedef struct {
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   318
	PyObject_HEAD
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   319
	A2DMX		ctm;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   320
	gstateColor	strokeColor;			/*strokeColor*/
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   321
	double		strokeWidth;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   322
	int			lineCap;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   323
	int			lineJoin;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   324
	double		strokeOpacity;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   325
	gstateColor	fillColor;			/*fill color*/
4306
8ffb2ffc283b support for Path autoclose & fillMode; version --> 3.3.29
robin
parents: 4303
diff changeset
   326
	int			fillMode;
4635
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   327
	int			textRenderMode;
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   328
	double		fillOpacity;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   329
	double		fontSize;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   330
	double		fontEMSize;			/*for scaling to points*/
2760
0658253b1e8a _renderPM.c: fix up fontName attribute handling so it does the right thing
rgbecker
parents: 2738
diff changeset
   331
	PyObject	*fontNameObj;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   332
#ifdef	RENDERPM_FT
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   333
	int			ft_font;			/*if we're trying ft_font things*/
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   334
#endif
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   335
	ArtSVP*		clipSVP;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   336
	pixBufT*	pixBuf;
1008
09e39778e2b5 changes to make it compile under MacOS:
jvr
parents: 994
diff changeset
   337
	int			pathLen, pathMax;	/*current and maximum sizes*/
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   338
	ArtBpath*	path;				/*the vector path data*/
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   339
	ArtVpathDash	dash;			/*for doing dashes*/
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   340
	Gt1EncodedFont*		font;		/*the currently set external font or NULL*/
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   341
	} gstateObject;
2510
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   342
static ArtBpath notdefPath[6]={
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   343
		{ART_MOVETO,0.0,0.0,0.0,0.0,726.0,0.0},
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   344
		{ART_LINETO,0.0,0.0,0.0,0.0,726.0,692.0},
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   345
		{ART_LINETO,0.0,0.0,0.0,0.0,35.0,692.0},
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   346
		{ART_LINETO,0.0,0.0,0.0,0.0,35.0,0.0},
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   347
		{ART_LINETO,0.0,0.0,0.0,0.0,726.0,0.0},
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   348
		{ART_END,0.0,0.0,0.0,0.0,0.0,0.0},
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   349
		};
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   350
1698
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   351
#ifdef	ROBIN_DEBUG
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   352
#define	GFMT	"%.17g"
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   353
#define PATHCODENAME(c) (c==ART_MOVETO_OPEN?"MOVETO":(c==ART_MOVETO?"MOVETO_C":(c==ART_LINETO?"LINETO":(c==ART_CURVETO?"CURVETO":(c==ART_END?"END":"????")))))
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   354
static	void dump_path(gstateObject* self)
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   355
{
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   356
	ArtBpath	*q = self->path;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   357
	size_t		i;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   358
	printf("strokeColor=%8.8xX%s strokeWidth=%g fillColor=%8.8xX%s\n", self->strokeColor.value,
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   359
			self->strokeColor.valid ? "valid":"invalid", self->strokeWidth,
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   360
			self->fillColor.value,
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   361
			self->fillColor.valid ? "valid":"invalid"
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   362
			);
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   363
	printf("ctm: " GFMT " " GFMT " " GFMT " " GFMT " " GFMT " " GFMT " det: " GFMT "\n", self->ctm[0], self->ctm[1], self->ctm[2], self->ctm[3], self->ctm[4], self->ctm[5],
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   364
		self->ctm[0]*self->ctm[3] - self->ctm[1]*self->ctm[2]);
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   365
	printf("path: pathLen=%d pathMax=%d\n",self->pathLen, self->pathMax);
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   366
	for(i=0;i<(size_t)self->pathLen;i++){
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   367
		char	*s;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   368
		printf("%3d: %-8s, (" GFMT "," GFMT "), (" GFMT "," GFMT "), (" GFMT "," GFMT ")\n",
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   369
				i, s=PATHCODENAME(q->code),
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   370
				q->x1,q->y1,q->x2,q->y2,q->x3,q->y3);
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   371
		if((q++)->code==ART_END || s[0]=='?') break;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   372
		}
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   373
	fflush(stdout);
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   374
}
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   375
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   376
void dump_vpath(char* msg, ArtVpath* q)
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   377
{
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   378
	size_t		i;
4306
8ffb2ffc283b support for Path autoclose & fillMode; version --> 3.3.29
robin
parents: 4303
diff changeset
   379
	printf("\n%s vpath:\n",msg);
1698
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   380
	for(i=0;i<10000;i++){
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   381
		char	*s;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   382
		printf("%3d: %-8s, (" GFMT "," GFMT ")\n",
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   383
				i, s=PATHCODENAME(q->code),
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   384
				q->x,q->y);
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   385
		if((q++)->code==ART_END || s[0]=='?') break;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   386
		}
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   387
	fflush(stdout);
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   388
}
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   389
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   390
void dump_svp(char* msg, ArtSVP* svp)
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   391
{
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   392
	int	i, j;
4306
8ffb2ffc283b support for Path autoclose & fillMode; version --> 3.3.29
robin
parents: 4303
diff changeset
   393
	printf("\n%s svp:\n",msg);
1698
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   394
	for(i=0;i<svp->n_segs;i++){
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   395
		ArtSVPSeg *s=svp->segs+i;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   396
		printf("seg%3d: n_points=%d dir=%s box=(" GFMT "," GFMT ") (" GFMT "," GFMT ")\n", i, s->n_points, s->dir?"dn":"up",s->bbox.x0,s->bbox.y0,s->bbox.x1,s->bbox.y1);
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   397
		for(j=0;j<s->n_points;j++) printf("    (" GFMT "," GFMT ")\n",s->points[j].x, s->points[j].y);
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   398
		}
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   399
	fflush(stdout);
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   400
}
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   401
#else
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   402
#define dump_path(p)
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   403
#define dump_vpath(m,p)
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   404
#define dump_svp(m,p)
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   405
#endif
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   406
1696
9c4859801f48 Minor cosmetic changes for gcc
rgbecker
parents: 1681
diff changeset
   407
static	void bpath_add_point(ArtBpath** pp, int* pn, int *pm, int code, double x[3], double y[3])
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   408
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   409
	int i = (*pn)++;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   410
	if(i == *pm) art_expand(*pp, ArtBpath, *pm);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   411
	(*pp)[i].code = code;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   412
	(*pp)[i].x1 = x[0];
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   413
	(*pp)[i].y1 = y[0];
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   414
	(*pp)[i].x2 = x[1];
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   415
	(*pp)[i].y2 = y[1];
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   416
	(*pp)[i].x3 = x[2];
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   417
	(*pp)[i].y3 = y[2];
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   418
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   419
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   420
static	PyObject*	_gstate_bpath_add(int c, char* fmt, gstateObject* self, PyObject* args)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   421
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   422
	double			x[3], y[3];
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   423
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   424
	if(!PyArg_ParseTuple(args,fmt,x+2,y+2)) return NULL;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   425
	x[0] = x[1] = y[0] = y[1] = 0;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   426
	bpath_add_point(&(self->path), &(self->pathLen), &(self->pathMax), c, x, y);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   427
	Py_INCREF(Py_None);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   428
	return Py_None;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   429
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   430
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   431
static	void gstate_pathEnd(gstateObject* self)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   432
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   433
	double			x[3];
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   434
	x[0] = x[1] = x[2] = 0;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   435
	bpath_add_point(&(self->path), &(self->pathLen), &(self->pathMax), ART_END, x, x);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   436
	self->pathLen--;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   437
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   438
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   439
static	PyObject*	gstate_moveTo(gstateObject* self, PyObject* args)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   440
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   441
	return _gstate_bpath_add(ART_MOVETO_OPEN,"dd:moveTo",self,args);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   442
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   443
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   444
static	PyObject*	gstate_moveToClosed(gstateObject* self, PyObject* args)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   445
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   446
	return _gstate_bpath_add(ART_MOVETO,"dd:moveToClosed",self,args);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   447
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   448
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   449
static	gstateObject*	_gstate_pathLenCheck(gstateObject* self)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   450
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   451
	if(!self->pathLen){
3753
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
   452
		PyErr_SetString(PyExc_ValueError, "_renderPM._gstate_pathLenCheck: path must begin with a moveTo");
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   453
		return NULL;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   454
		}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   455
	return self;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   456
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   457
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   458
static	PyObject*	gstate_lineTo(gstateObject* self, PyObject* args)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   459
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   460
	if(!_gstate_pathLenCheck(self)) return NULL;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   461
	return _gstate_bpath_add(ART_LINETO,"dd:lineTo",self,args);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   462
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   463
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   464
static	PyObject*	gstate_curveTo(gstateObject* self, PyObject* args)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   465
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   466
	double			x[3], y[3];
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   467
	if(!_gstate_pathLenCheck(self)) return NULL;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   468
	if(!PyArg_ParseTuple(args,"dddddd:curveTo",x+0,y+0,x+1,y+1,x+2,y+2)) return NULL;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   469
	bpath_add_point(&(self->path), &(self->pathLen), &(self->pathMax), ART_CURVETO, x, y);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   470
	Py_INCREF(Py_None);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   471
	return Py_None;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   472
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   473
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   474
static	PyObject*	gstate_pathBegin(gstateObject* self, PyObject* args)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   475
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   476
	if(!PyArg_ParseTuple(args,":pathBegin")) return NULL;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   477
	self->pathLen = 0;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   478
	Py_INCREF(Py_None);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   479
	return Py_None;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   480
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   481
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   482
static	double _norm1diff(ArtBpath *p, ArtBpath *q)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   483
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   484
	double rx = p->x3-q->x3;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   485
	double ry = p->y3-q->y3;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   486
	if(rx<0) rx = -rx;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   487
	if(ry<0) ry = -ry;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   488
	if(rx<=ry) return ry;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   489
	return rx;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   490
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   491
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   492
static	PyObject*	gstate_pathClose(gstateObject* self, PyObject* args)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   493
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   494
	int	c;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   495
	ArtBpath	*p, *q, *q0;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   496
	double		x[3], y[3];
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   497
	if(!PyArg_ParseTuple(args,":pathClose")) return NULL;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   498
	p = self->path;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   499
	for(q0 = q = p + self->pathLen-1;q>=p;q--){
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   500
		c = q->code;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   501
		if(c==ART_MOVETO_OPEN){
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   502
			q->code = ART_MOVETO;	/*this closes it*/
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   503
			if(_norm1diff(q,q0)>1e-8){
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   504
				x[0] = x[1] = y[0] = y[1] = 0.0;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   505
				x[2] = q->x3;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   506
				y[2] = q->y3;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   507
				bpath_add_point(&self->path,&self->pathLen,&self->pathMax,ART_LINETO,x,y);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   508
				}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   509
			break;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   510
			}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   511
		else if(c==ART_MOVETO){
3753
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
   512
			PyErr_SetString(PyExc_ValueError, "_renderPM.gstate_pathClose: path already closed");
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   513
			return NULL;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   514
			}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   515
		}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   516
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   517
	if(q<p){
3753
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
   518
		PyErr_SetString(PyExc_ValueError, "_renderPM.gstate_pathClose: bpath has no MOVETO");
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   519
		return NULL;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   520
		}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   521
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   522
	Py_INCREF(Py_None);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   523
	return Py_None;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   524
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   525
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   526
static	PyObject* gstate_clipPathClear(gstateObject* self, PyObject* args)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   527
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   528
	if(!PyArg_ParseTuple(args,":clipPathClear")) return NULL;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   529
	if(self->clipSVP){
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   530
		art_svp_free(self->clipSVP);
1227
b12e12198e8c Robert Kern's clip path fixes
rgbecker
parents: 1008
diff changeset
   531
		self->clipSVP = NULL;
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   532
		}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   533
	Py_INCREF(Py_None);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   534
	return Py_None;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   535
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   536
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   537
static art_u32 _RGBA(art_u32 rgb, double alpha)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   538
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   539
	art_u32 tmp = ((int)(0xFF * alpha))&0xFF;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   540
	return (rgb << 8) | tmp;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   541
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   542
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   543
static void _vpath_segment_reverse(ArtVpath *p, ArtVpath *q)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   544
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   545
	if(p<q){
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   546
		ArtPathcode c;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   547
		ArtVpath *b= p, *e = q;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   548
		while(b<e){
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   549
			ArtVpath s = *b;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   550
			*b++ = *e;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   551
			*e-- = s;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   552
			}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   553
		c = p->code;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   554
		p->code = q->code;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   555
		q->code = c;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   556
		}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   557
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   558
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   559
static	void _vpath_reverse(ArtVpath *p)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   560
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   561
	ArtVpath	*q = p;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   562
	while(q->code!=ART_END){
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   563
		while((++p)->code==ART_LINETO);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   564
		_vpath_segment_reverse( q, p-1 );
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   565
		q = p;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   566
		}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   567
}
1316
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
   568
1698
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   569
static double _vpath_segment_area(ArtVpath *p, ArtVpath *q)
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   570
{
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   571
	double a=0.0, x0,y0, x1,y1;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   572
	if(p->code==ART_MOVETO){
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   573
		ArtVpath* p0 = p;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   574
		while(p<q){
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   575
			x0 = p->x;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   576
			y0 = (p++)->y;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   577
			if(p==q){
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   578
				x1 = p0->x;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   579
				y1 = p0->y;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   580
				}
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   581
			else{
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   582
				x1 = p->x;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   583
				y1 = p->y;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   584
				}
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   585
			a += x1*y0 - x0*y1;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   586
			}
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   587
		}
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   588
	return a;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   589
}
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   590
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   591
static double _vpath_area(ArtVpath *p)
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   592
{
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   593
	double a=0.0, t;
1702
119f866947fa Use automatic orientation
rgbecker
parents: 1698
diff changeset
   594
	ArtVpath	*q = p, *p0=p;
1698
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   595
	while(q->code!=ART_END){
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   596
		while((++p)->code==ART_LINETO);
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   597
		t = _vpath_segment_area( q, p);
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   598
#ifdef	ROBIN_DEBUG
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   599
		printf("	closed segment area=%g\n", t );
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   600
#endif
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   601
		a += t;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   602
		q = p;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   603
		}
1702
119f866947fa Use automatic orientation
rgbecker
parents: 1698
diff changeset
   604
	if(a<=-1e-8) _vpath_reverse( p0 );
1698
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   605
	return a;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   606
}
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   607
4635
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   608
static	void _gstate_clipPathSetOrAdd(gstateObject* self, int fillMode, int add, int endIt){
1698
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   609
	ArtVpath	*vpath;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   610
	ArtVpath	*trVpath;
4640
626937a80b64 cosmetic changes and add gstate setattr for fontSize
robin
parents: 4635
diff changeset
   611
	if (fillMode==FILL_UNSET) fillMode = self->fillMode;
4635
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   612
	if(endIt) gstate_pathEnd(self);
1698
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   613
	dump_path(self);
4593
765c7f6801b5 fix barchart axis crossing, nano eedit to _renderPM.c; version-->3.5.45
robin
parents: 4508
diff changeset
   614
	vpath = art_bez_path_to_vec(self->path, VECSP);
1698
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   615
	dump_vpath("after -->vec",vpath);
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   616
	trVpath = art_vpath_affine_transform (vpath, self->ctm);
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   617
	_vpath_area(trVpath);
4635
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   618
	if (add) {
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   619
		ArtSVP		*newSVP = art_svp_from_vpath(trVpath);
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   620
		if(self->clipSVP) {
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   621
			ArtSVP *oldSVP = self->clipSVP;
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   622
			self->clipSVP = art_svp_union(oldSVP,newSVP);
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   623
			art_svp_free(oldSVP);
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   624
			art_svp_free(newSVP);
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   625
			}
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   626
		else{
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   627
			self->clipSVP = newSVP;
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   628
			}
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   629
		}
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   630
	else{
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   631
		if(self->clipSVP) art_svp_free(self->clipSVP);
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   632
		self->clipSVP = art_svp_from_vpath(trVpath);
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   633
		}
1698
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   634
	art_free(trVpath);
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   635
	art_free(vpath);
4635
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   636
}
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   637
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   638
static	PyObject* gstate_clipPathSet(gstateObject* self, PyObject* args)
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   639
{
4640
626937a80b64 cosmetic changes and add gstate setattr for fontSize
robin
parents: 4635
diff changeset
   640
	int			fillMode = FILL_UNSET;
4635
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   641
	if(!PyArg_ParseTuple(args,"|i:clipPathSet",&fillMode)) return NULL;
4640
626937a80b64 cosmetic changes and add gstate setattr for fontSize
robin
parents: 4635
diff changeset
   642
	_gstate_clipPathSetOrAdd(self, fillMode, 0, 1); /*fill add endIt*/
4635
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   643
	Py_INCREF(Py_None);
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   644
	return Py_None;
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   645
}
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   646
static	PyObject* gstate_clipPathAdd(gstateObject* self, PyObject* args)
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   647
{
4640
626937a80b64 cosmetic changes and add gstate setattr for fontSize
robin
parents: 4635
diff changeset
   648
	int			fillMode = FILL_UNSET;
4635
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   649
	if(!PyArg_ParseTuple(args,"|i:clipPathAdd",&fillMode)) return NULL;
4640
626937a80b64 cosmetic changes and add gstate setattr for fontSize
robin
parents: 4635
diff changeset
   650
	_gstate_clipPathSetOrAdd(self, fillMode, 1, 1) /*fill add endIt*/;
1698
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   651
	Py_INCREF(Py_None);
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   652
	return Py_None;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   653
}
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   654
4306
8ffb2ffc283b support for Path autoclose & fillMode; version --> 3.3.29
robin
parents: 4303
diff changeset
   655
static void _gstate_pathFill(gstateObject* self,int endIt, int vpReverse, int fillMode)
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   656
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   657
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   658
	if(self->fillColor.valid){
4457
2cb3dd1e5bc2 try to fix gcc compile errors
robin <robin@reportlab.com>
parents: 4455
diff changeset
   659
		ArtVpath	*vpath, *trVpath, *tmp_vpath;
1681
129ddacd8869 Rendering fixes & changes for Dinu's image shape
rgbecker
parents: 1676
diff changeset
   660
		ArtSVP		*svp, *tmp_svp;
129ddacd8869 Rendering fixes & changes for Dinu's image shape
rgbecker
parents: 1676
diff changeset
   661
		pixBufT*	p;
2042
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   662
		double		a;
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   663
		if(endIt) gstate_pathEnd(self);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   664
		dump_path(self);
4593
765c7f6801b5 fix barchart axis crossing, nano eedit to _renderPM.c; version-->3.5.45
robin
parents: 4508
diff changeset
   665
		vpath = art_bez_path_to_vec(self->path, VECSP);
1702
119f866947fa Use automatic orientation
rgbecker
parents: 1698
diff changeset
   666
		if(0 && vpReverse) _vpath_reverse(vpath);
1681
129ddacd8869 Rendering fixes & changes for Dinu's image shape
rgbecker
parents: 1676
diff changeset
   667
		trVpath =  art_vpath_affine_transform(vpath, self->ctm);
2042
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   668
		a = _vpath_area(trVpath);
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   669
		if(fabs(a)>1e-7){
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   670
			/*fill only larger things*/
4455
c637072fda31 use randomization for fills (svglib issue 104)
robin <robin@reportlab.com>
parents: 4451
diff changeset
   671
			tmp_vpath =  art_vpath_perturb(trVpath);
4604
e286458cd0c7 fix memory leak in _renderPM.c
robin
parents: 4601
diff changeset
   672
			art_free(trVpath);	/*free the original*/
e286458cd0c7 fix memory leak in _renderPM.c
robin
parents: 4601
diff changeset
   673
			trVpath =  tmp_vpath;
2042
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   674
			svp = art_svp_from_vpath(trVpath);
4306
8ffb2ffc283b support for Path autoclose & fillMode; version --> 3.3.29
robin
parents: 4303
diff changeset
   675
			dump_svp("fill svp from vpath",svp);
4640
626937a80b64 cosmetic changes and add gstate setattr for fontSize
robin
parents: 4635
diff changeset
   676
			if(fillMode==FILL_EVEN_ODD){
4306
8ffb2ffc283b support for Path autoclose & fillMode; version --> 3.3.29
robin
parents: 4303
diff changeset
   677
				tmp_svp = art_svp_uncross(svp);
8ffb2ffc283b support for Path autoclose & fillMode; version --> 3.3.29
robin
parents: 4303
diff changeset
   678
				dump_svp("fill svp uncrossed",tmp_svp);
8ffb2ffc283b support for Path autoclose & fillMode; version --> 3.3.29
robin
parents: 4303
diff changeset
   679
				art_svp_free(svp);
4640
626937a80b64 cosmetic changes and add gstate setattr for fontSize
robin
parents: 4635
diff changeset
   680
				svp = art_svp_rewind_uncrossed(tmp_svp,fillMode==FILL_EVEN_ODD ? ART_WIND_RULE_ODDEVEN : ART_WIND_RULE_NONZERO);
4306
8ffb2ffc283b support for Path autoclose & fillMode; version --> 3.3.29
robin
parents: 4303
diff changeset
   681
				art_svp_free(tmp_svp);
4640
626937a80b64 cosmetic changes and add gstate setattr for fontSize
robin
parents: 4635
diff changeset
   682
			}
2042
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   683
			if(self->clipSVP) {
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   684
				tmp_svp = svp;
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   685
				dump_svp("fill clip svp path",self->clipSVP);
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   686
				dump_svp("fill svp orig",svp);
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   687
				svp = art_svp_intersect(tmp_svp, self->clipSVP);
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   688
				art_svp_free(tmp_svp);
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   689
				}
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   690
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   691
#ifdef	ROBIN_DEBUG
2042
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   692
			printf("fillColor=0x%8.8x, opacity=" GFMT " -->0x%8.8x\n",self->fillColor.value, self->fillOpacity, _RGBA(self->fillColor.value, self->fillOpacity));
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   693
			dump_vpath("fill vpath", vpath);
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   694
			dump_vpath("fill trVpath", trVpath);
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   695
			dump_svp("fill svp",svp);
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   696
#endif
2042
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   697
			p = self->pixBuf;
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   698
			art_rgb_svp_alpha(svp,
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   699
							 0,0,
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   700
							 p->width, p->height,
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   701
							 _RGBA(self->fillColor.value, self->fillOpacity),
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   702
							 p->buf,
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   703
							 p->rowstride,
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   704
							 NULL);
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   705
2042
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   706
			art_svp_free(svp);
e4208a6d992f Attempt to eliminate small area fills
rgbecker
parents: 2033
diff changeset
   707
			}
2110
cca387467c50 Fixed memory family problems
rgbecker
parents: 2108
diff changeset
   708
		art_free(trVpath);
cca387467c50 Fixed memory family problems
rgbecker
parents: 2108
diff changeset
   709
		art_free(vpath);
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   710
		}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   711
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   712
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   713
static PyObject* gstate_pathFill(gstateObject* self, PyObject* args)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   714
{
4306
8ffb2ffc283b support for Path autoclose & fillMode; version --> 3.3.29
robin
parents: 4303
diff changeset
   715
	int			fillMode = self->fillMode;
8ffb2ffc283b support for Path autoclose & fillMode; version --> 3.3.29
robin
parents: 4303
diff changeset
   716
	if(!PyArg_ParseTuple(args,"|i:pathFill",&fillMode)) return NULL;
4640
626937a80b64 cosmetic changes and add gstate setattr for fontSize
robin
parents: 4635
diff changeset
   717
	_gstate_pathFill(self,1,0,fillMode); /*endIt vpReverse(ignored) fillMode*/
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   718
	Py_INCREF(Py_None);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   719
	return Py_None;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   720
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   721
4635
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   722
static void _gstate_pathStroke(gstateObject* self, int endIt)
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   723
{
1698
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   724
	ArtVpath	*vpath=NULL, *trVpath;
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   725
	ArtSVP*		svp=NULL;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   726
	ArtSVP*		tmp_svp=NULL;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   727
	pixBufT*	p;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   728
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   729
	if(self->strokeColor.valid && self->strokeWidth>0){
4635
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   730
		if(endIt) gstate_pathEnd(self);
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   731
		dump_path(self);
4593
765c7f6801b5 fix barchart axis crossing, nano eedit to _renderPM.c; version-->3.5.45
robin
parents: 4508
diff changeset
   732
		vpath = art_bez_path_to_vec(self->path, VECSP);
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   733
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   734
		if(self->dash.dash){
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   735
			ArtVpath*	tvpath=vpath;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   736
			vpath = art_vpath_dash(tvpath, &self->dash);
2110
cca387467c50 Fixed memory family problems
rgbecker
parents: 2108
diff changeset
   737
			art_free(tvpath);
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   738
			}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   739
		dump_vpath("stroke vpath", vpath);
1698
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   740
		trVpath = art_vpath_affine_transform(vpath, self->ctm);
1702
119f866947fa Use automatic orientation
rgbecker
parents: 1698
diff changeset
   741
		_vpath_area(trVpath);
1698
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   742
		svp = art_svp_vpath_stroke(trVpath, self->lineJoin, self->lineCap, self->strokeWidth, 4, 0.5);
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   743
		art_free(trVpath);
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   744
		if(self->clipSVP){
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   745
			tmp_svp = svp;
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   746
			dump_svp("stroke clip svp path",self->clipSVP);
ec36871f4d91 Experimental stuff
rgbecker
parents: 1696
diff changeset
   747
			dump_svp("stroke svp orig",svp);
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   748
			svp = art_svp_intersect(tmp_svp, self->clipSVP);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   749
			art_svp_free(tmp_svp);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   750
			}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   751
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   752
		dump_svp("stroke svp",svp);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   753
		p = self->pixBuf;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   754
		art_rgb_svp_alpha(svp,
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   755
						 0,0,
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   756
						 p->width, p->height,
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   757
						 _RGBA(self->strokeColor.value, self->strokeOpacity),
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   758
						 p->buf,
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   759
						 p->rowstride,
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   760
						 NULL);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   761
		art_svp_free(svp);
2110
cca387467c50 Fixed memory family problems
rgbecker
parents: 2108
diff changeset
   762
		art_free(vpath);
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   763
		}
4635
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   764
}
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   765
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   766
static PyObject* gstate_pathStroke(gstateObject* self, PyObject* args)
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   767
{
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   768
	if(!PyArg_ParseTuple(args,":pathStroke")) return NULL;
4640
626937a80b64 cosmetic changes and add gstate setattr for fontSize
robin
parents: 4635
diff changeset
   769
	_gstate_pathStroke(self, 1);	/*endIt*/
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   770
	Py_INCREF(Py_None);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   771
	return Py_None;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   772
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   773
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   774
#ifdef	RENDERPM_FT
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   775
typedef struct	{
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   776
		ArtBpath	*path;
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   777
		int			pathLen, pathMax;	/*current and maximum sizes*/
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   778
		} _ft_outliner_user_t;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   779
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   780
static int _ft_move_to(FT_Vector* to, void* user)
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   781
{
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   782
	_ft_outliner_user_t *self = (_ft_outliner_user_t*)user;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   783
	double x[3], y[3];
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   784
	x[0] = x[1] = y[0] = y[1] = 0;
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   785
	x[2] = to->x;
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   786
	y[2] = to->y;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   787
	bpath_add_point(&(self->path), &(self->pathLen), &(self->pathMax), ART_MOVETO, x, y);
2114
26c636b61f7f TTFONTS Render
rgbecker
parents: 2111
diff changeset
   788
	return 0;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   789
}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   790
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   791
static int _ft_line_to(FT_Vector* to, void*  user)
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   792
{
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   793
	_ft_outliner_user_t *self = (_ft_outliner_user_t*)user;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   794
	double	x[3], y[3];
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   795
	x[0] = x[1] = y[0] = y[1] = 0;
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   796
	x[2] = to->x;
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   797
	y[2] = to->y;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   798
	bpath_add_point(&(self->path), &(self->pathLen), &(self->pathMax), ART_LINETO, x, y);
2114
26c636b61f7f TTFONTS Render
rgbecker
parents: 2111
diff changeset
   799
	return 0;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   800
}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   801
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   802
static int _ft_cubic_to( FT_Vector*  control1, FT_Vector*  control2, FT_Vector*  to, void*       user )
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   803
{
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   804
	_ft_outliner_user_t *self = (_ft_outliner_user_t*)user;
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   805
	double	x[3], y[3];
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   806
	x[0] = control1->x;
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   807
	y[0] = control1->y;
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   808
	x[1] = control2->x;
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   809
	y[1] = control2->y;
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   810
	x[2] = to->x;
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   811
	y[2] = to->y;
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   812
	bpath_add_point(&(self->path), &(self->pathLen), &(self->pathMax), ART_CURVETO, x, y);
2114
26c636b61f7f TTFONTS Render
rgbecker
parents: 2111
diff changeset
   813
	return 0;
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   814
}
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   815
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   816
static int _ft_conic_to( FT_Vector*  control, FT_Vector*  to, void*  user )
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   817
{
2784
0fd68687a5ec _renderPM.c: 1.04 fixes stupid quadratic bezier to cubic conversion bug
rgbecker
parents: 2760
diff changeset
   818
	_ft_outliner_user_t *self = (_ft_outliner_user_t*)user;
0fd68687a5ec _renderPM.c: 1.04 fixes stupid quadratic bezier to cubic conversion bug
rgbecker
parents: 2760
diff changeset
   819
	int	i=self->pathLen - 1;
0fd68687a5ec _renderPM.c: 1.04 fixes stupid quadratic bezier to cubic conversion bug
rgbecker
parents: 2760
diff changeset
   820
	FT_Vector p1, p2;
0fd68687a5ec _renderPM.c: 1.04 fixes stupid quadratic bezier to cubic conversion bug
rgbecker
parents: 2760
diff changeset
   821
	FT_Pos	x0=(FT_Pos)self->path[i].x3, y0=(FT_Pos)self->path[i].y3, x1=control->x, y1=control->y;
0fd68687a5ec _renderPM.c: 1.04 fixes stupid quadratic bezier to cubic conversion bug
rgbecker
parents: 2760
diff changeset
   822
	p1.x = x0+((x1-x0)*2)/3;
0fd68687a5ec _renderPM.c: 1.04 fixes stupid quadratic bezier to cubic conversion bug
rgbecker
parents: 2760
diff changeset
   823
	p1.y = y0+((y1-y0)*2)/3;
0fd68687a5ec _renderPM.c: 1.04 fixes stupid quadratic bezier to cubic conversion bug
rgbecker
parents: 2760
diff changeset
   824
	p2.x = x1+(to->x-x1)/3;
0fd68687a5ec _renderPM.c: 1.04 fixes stupid quadratic bezier to cubic conversion bug
rgbecker
parents: 2760
diff changeset
   825
	p2.y = y1+(to->y-y1)/3;
0fd68687a5ec _renderPM.c: 1.04 fixes stupid quadratic bezier to cubic conversion bug
rgbecker
parents: 2760
diff changeset
   826
	return _ft_cubic_to(&p1, &p2, to, user);
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   827
}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   828
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   829
static FT_Outline_Funcs _ft_outliner = {
2911
b02894dafb25 rl_addons: python2.5 vs amd64 changes
rptlab
parents: 2907
diff changeset
   830
	(FT_Outline_MoveTo_Func)_ft_move_to,
b02894dafb25 rl_addons: python2.5 vs amd64 changes
rptlab
parents: 2907
diff changeset
   831
	(FT_Outline_LineTo_Func)_ft_line_to,
b02894dafb25 rl_addons: python2.5 vs amd64 changes
rptlab
parents: 2907
diff changeset
   832
	(FT_Outline_ConicTo_Func)_ft_conic_to,
b02894dafb25 rl_addons: python2.5 vs amd64 changes
rptlab
parents: 2907
diff changeset
   833
	(FT_Outline_CubicTo_Func)_ft_cubic_to,
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   834
	0,
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   835
	0
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   836
	};
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   837
2559
c6b086e81923 rl_addons: changes for building in freeBSD environment
rgbecker
parents: 2510
diff changeset
   838
#include FT_OUTLINE_H
2114
26c636b61f7f TTFONTS Render
rgbecker
parents: 2111
diff changeset
   839
static ArtBpath *_ft_get_glyph_outline(FT_Face face, int c, _ft_outliner_user_t *user, double *pw)
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   840
{
2114
26c636b61f7f TTFONTS Render
rgbecker
parents: 2111
diff changeset
   841
	int	err, idx;
26c636b61f7f TTFONTS Render
rgbecker
parents: 2111
diff changeset
   842
	if(!(idx=FT_Get_Char_Index(face,c)) || (err=FT_Load_Glyph(face,idx,FT_LOAD_NO_SCALE|FT_LOAD_NO_BITMAP))){
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   843
		return NULL;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   844
		}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   845
	if(face->glyph->format!=FT_GLYPH_FORMAT_OUTLINE){
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   846
		return NULL;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   847
		}
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   848
	if((err=FT_Outline_Decompose( &face->glyph->outline, &_ft_outliner, (void*)user))){
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   849
		return NULL;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   850
		}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   851
	else{
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   852
		double	x[3];
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   853
		x[0] = x[1] = x[2] = 0;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   854
		bpath_add_point(&(user->path), &(user->pathLen), &(user->pathMax), ART_END, x, x);
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   855
		user->pathLen--;
2114
26c636b61f7f TTFONTS Render
rgbecker
parents: 2111
diff changeset
   856
		*pw = face->glyph->metrics.horiAdvance;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   857
		}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   858
	return user->path;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   859
}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   860
#endif
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   861
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   862
static PyObject* gstate_drawString(gstateObject* self, PyObject* args)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   863
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   864
	A2DMX	orig, trans = {1,0,0,1,0,0}, scaleMat = {1,0,0,1,0,0};
2114
26c636b61f7f TTFONTS Render
rgbecker
parents: 2111
diff changeset
   865
	double	scaleFactor, x, y, w;
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   866
	char*	text;
4635
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   867
	int		c, i, textRenderMode=self->textRenderMode;
4508
5f79dd4e0cc8 add some fixes inspired by Marius Gedminas as a partial fix of bb issue #174
robin <robin@reportlab.com>
parents: 4458
diff changeset
   868
	Py_ssize_t	textlen;
2510
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   869
	ArtBpath	*saved_path, *path;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   870
	void	*font = self->font;
3985
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   871
	PyObject	*textObj, *obj0;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   872
#ifdef	RENDERPM_FT
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
   873
	int				ft_font = self->ft_font;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   874
	Py_UNICODE		*utext;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   875
	_ft_outliner_user_t _ft_data;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   876
#endif
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   877
	if(!font){
3753
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
   878
		PyErr_SetString(PyExc_ValueError, "_renderPM.gstate_drawString: No font set!");
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   879
		return NULL;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   880
		}
3985
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   881
	if(!PyArg_ParseTuple(args,"ddO:drawString", &x, &y, &textObj)) return NULL;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   882
#ifdef	RENDERPM_FT
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   883
	if(ft_font){
3985
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   884
		/*we need unicode*/
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   885
		if(PyUnicode_Check(textObj)){
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   886
			obj0 = textObj;
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   887
			}
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   888
		else if(PyBytes_Check(textObj)){
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   889
			text = PyBytes_AsString(textObj);
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   890
			textlen = PyBytes_GET_SIZE(textObj);
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   891
			obj0 = PyUnicode_DecodeUTF8(text, textlen,NULL);
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   892
			if(!obj0) return NULL;
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   893
			}
4042
6382a792db9e _renderPM.c: move some labels to safer positions
robin
parents: 3985
diff changeset
   894
		else goto L0;
3985
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   895
		textlen = PyUnicode_GetSize(obj0);
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   896
		utext = PyUnicode_AsUnicode(obj0);
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   897
		_ft_data.pathMax = 0;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   898
		_ft_data.path = NULL;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   899
		}
3985
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   900
	else {
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   901
#endif
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   902
		/*we need bytes*/
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   903
		if(PyUnicode_Check(textObj)){
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   904
			obj0 = PyUnicode_AsUTF8String(textObj);
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   905
			if(!obj0) return NULL;
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   906
			}
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   907
		else if(PyBytes_Check(textObj)){
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   908
			obj0 = textObj;
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   909
			}
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   910
		else goto L0;
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   911
		text = PyBytes_AsString(obj0);
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   912
		textlen = PyBytes_GET_SIZE(obj0);
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   913
#ifdef	RENDERPM_FT
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   914
		}
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   915
#endif
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   916
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   917
	/*save ctm*/
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   918
	memcpy(orig, self->ctm, sizeof(A2DMX));
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   919
	saved_path = self->path;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   920
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   921
	/* translate to x, y */
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   922
	trans[4] = x;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   923
	trans[5] = y;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   924
	art_affine_multiply(self->ctm,trans,self->ctm);
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   925
	scaleFactor = self->fontSize/self->fontEMSize;	/*apply font scaling*/
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   926
	scaleMat[0] = scaleFactor;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   927
#ifdef FLIPY
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   928
	scaleMat[3] = -scaleFactor;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   929
#else
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   930
	scaleMat[3] = scaleFactor;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   931
#endif
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   932
	art_affine_multiply(self->ctm, scaleMat, self->ctm);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   933
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   934
	/*here we render each character one by one, lacks efficiency once again*/
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   935
	trans[5] = 0;
2111
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   936
	for(i=0;i<textlen;i++){
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   937
#ifdef	RENDERPM_FT
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   938
		if(ft_font){
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   939
			_ft_data.pathLen = 0;
2111
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   940
			c = utext[i];
2510
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   941
			path = _ft_get_glyph_outline((FT_Face)font,c,&_ft_data,&w);
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   942
			if(!path){
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   943
				_ft_data.pathLen = 0;
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   944
				path = _ft_get_glyph_outline((FT_Face)font,0,&_ft_data,&w);
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   945
				}
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   946
			}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   947
		else{
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   948
#endif
2111
a97d72a323db Now compiles and runs, fails to draw TTF though
rgbecker
parents: 2110
diff changeset
   949
		c = (text[i])&0xff;
2510
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   950
		path = gt1_get_glyph_outline((Gt1EncodedFont*)font, c, &w);	/*ascii encoding for the moment*/
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   951
		if(!path){
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   952
			path = notdefPath;
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   953
			w = 761;
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   954
			}
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   955
#ifdef	RENDERPM_FT
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   956
		}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   957
#endif
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   958
2510
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   959
		if(path){
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   960
			self->path = path;
4635
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   961
			if (textRenderMode==0 || textRenderMode==2 || textRenderMode==4 || textRenderMode==6)
4640
626937a80b64 cosmetic changes and add gstate setattr for fontSize
robin
parents: 4635
diff changeset
   962
				_gstate_pathFill(self,0,1,FILL_NON_ZERO) /*endit vpReverse(ignored) fillMode*/;
4635
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   963
			if (textRenderMode==1 || textRenderMode==2 || textRenderMode==5 || textRenderMode==6)
4640
626937a80b64 cosmetic changes and add gstate setattr for fontSize
robin
parents: 4635
diff changeset
   964
				_gstate_pathStroke(self,0);	/*endIt*/
4635
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   965
			if (textRenderMode>=4)
4640
626937a80b64 cosmetic changes and add gstate setattr for fontSize
robin
parents: 4635
diff changeset
   966
				_gstate_clipPathSetOrAdd(self, -1, 1, 0);	/*fill add endIt*/
4635
b60508f2fd12 shapes.String class supports textRenderMode; some fillMode fixes; version --> 3.5.60
robin
parents: 4621
diff changeset
   967
2114
26c636b61f7f TTFONTS Render
rgbecker
parents: 2111
diff changeset
   968
#ifdef	RENDERPM_FT
2510
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   969
			if(!ft_font && path!=notdefPath)
2114
26c636b61f7f TTFONTS Render
rgbecker
parents: 2111
diff changeset
   970
#endif
2510
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   971
			art_free(path);
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   972
			}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   973
		else {
2510
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
   974
			w = 761;
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   975
			}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   976
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   977
		/*move to right, scaling width by xscale and don't allow rotations or skew in CTM */
2114
26c636b61f7f TTFONTS Render
rgbecker
parents: 2111
diff changeset
   978
		trans[4] = w;	/*units are em units right?*/
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   979
		art_affine_multiply(self->ctm, trans, self->ctm);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   980
		}
3985
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
   981
	if(textObj!=obj0) Py_DECREF(obj0);
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   982
#ifdef	RENDERPM_FT
2114
26c636b61f7f TTFONTS Render
rgbecker
parents: 2111
diff changeset
   983
	if(ft_font) art_free(_ft_data.path);
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
   984
#endif
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   985
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   986
	/*restore original ctm*/
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   987
	memcpy(self->ctm, orig, sizeof(A2DMX));
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   988
	self->path = saved_path;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   989
	Py_INCREF(Py_None);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   990
	return Py_None;
4042
6382a792db9e _renderPM.c: move some labels to safer positions
robin
parents: 3985
diff changeset
   991
6382a792db9e _renderPM.c: move some labels to safer positions
robin
parents: 3985
diff changeset
   992
L0:	PyErr_SetString(PyExc_ValueError, "_renderPM.gstate_drawString: text must be bytes/unicode!");
6382a792db9e _renderPM.c: move some labels to safer positions
robin
parents: 3985
diff changeset
   993
	return NULL;
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   994
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
   995
1316
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
   996
static PyObject* _fmtPathElement(ArtBpath *p, char* name, int n)
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
   997
{
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
   998
	PyObject	*P = PyTuple_New(n+1);
3753
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
   999
	PyTuple_SET_ITEM(P, 0, PyUnicode_FromString(name));
1316
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1000
	if(n==6){
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1001
		PyTuple_SET_ITEM(P, 1, PyFloat_FromDouble(p->x1));
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1002
		PyTuple_SET_ITEM(P, 2, PyFloat_FromDouble(p->y1));
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1003
		PyTuple_SET_ITEM(P, 3, PyFloat_FromDouble(p->x2));
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1004
		PyTuple_SET_ITEM(P, 4, PyFloat_FromDouble(p->y2));
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1005
		PyTuple_SET_ITEM(P, 5, PyFloat_FromDouble(p->x3));
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1006
		PyTuple_SET_ITEM(P, 6, PyFloat_FromDouble(p->y3));
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1007
		}
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1008
	else {
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1009
		PyTuple_SET_ITEM(P, 1, PyFloat_FromDouble(p->x3));
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1010
		PyTuple_SET_ITEM(P, 2, PyFloat_FromDouble(p->y3));
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1011
		}
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1012
	return P;
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1013
}
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1014
3386
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1015
static PyObject* _fmtVPathElement(ArtVpath *p, char* name, int n)
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1016
{
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1017
	PyObject	*P = PyTuple_New(n+1);
3753
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
  1018
	PyTuple_SET_ITEM(P, 0, PyUnicode_FromString(name));
3386
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1019
	PyTuple_SET_ITEM(P, 1, PyFloat_FromDouble(p->x));
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1020
	PyTuple_SET_ITEM(P, 2, PyFloat_FromDouble(p->y));
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1021
	return P;
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1022
}
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1023
1316
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1024
static PyObject* _get_gstatePath(int n, ArtBpath* path)
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1025
{
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1026
	PyObject	*P = PyTuple_New(n);
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1027
	PyObject	*e;
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1028
	ArtBpath	*p;
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1029
	int			i;
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1030
	for(i=0;i<n;i++){
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1031
		p = path+i;
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1032
		switch(p->code){
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1033
			case ART_MOVETO_OPEN:
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1034
				e = _fmtPathElement(p,"moveTo",2);
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1035
				break;
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1036
			case ART_MOVETO:
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1037
				e = _fmtPathElement(p,"moveToClosed",2);
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1038
				break;
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1039
			case ART_LINETO:
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1040
				e = _fmtPathElement(p,"lineTo",2);
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1041
				break;
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1042
			case ART_CURVETO:
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1043
				e = _fmtPathElement(p,"curveTo",6);
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1044
				break;
3753
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
  1045
			case ART_END:
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
  1046
				break;
1316
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1047
			}
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1048
		PyTuple_SET_ITEM(P, i, e);
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1049
		}
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1050
	return P;
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1051
}
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1052
3386
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1053
static PyObject* _get_gstateVPath(gstateObject *self)
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1054
{
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1055
	PyObject	*e, *P;
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1056
	ArtVpath	*vpath, *v;
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1057
	int			i;
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1058
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1059
	gstate_pathEnd(self);
4593
765c7f6801b5 fix barchart axis crossing, nano eedit to _renderPM.c; version-->3.5.45
robin
parents: 4508
diff changeset
  1060
	v = vpath = art_bez_path_to_vec(self->path, VECSP);
3386
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1061
	while(v->code!=ART_END) v++;
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1062
	P = PyTuple_New(v-vpath);
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1063
	i = 0;
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1064
	v =vpath;
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1065
	while(v->code!=ART_END){
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1066
		switch(v->code){
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1067
			case ART_MOVETO_OPEN:
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1068
				e = _fmtVPathElement(v,"moveTo",2);
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1069
				break;
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1070
			case ART_MOVETO:
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1071
				e = _fmtVPathElement(v,"moveToClosed",2);
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1072
				break;
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1073
			case ART_LINETO:
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1074
				e = _fmtVPathElement(v,"lineTo",2);
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1075
				break;
3753
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
  1076
			case ART_CURVETO:
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
  1077
			case ART_END:
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
  1078
				break;
3386
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1079
			}
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1080
		PyTuple_SET_ITEM(P, i, e);
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1081
		v++;
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1082
		i++;
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1083
		}
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1084
	art_free(vpath);
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1085
	return P;
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1086
}
2bfeb67b4d9d _renderPM.c: v1.07 adds gstate.vpath to obtain linearized paths
rgbecker
parents: 2965
diff changeset
  1087
1321
6a1f7686da39 Renamed stringPath to _stringPath and improved it
rgbecker
parents: 1316
diff changeset
  1088
static PyObject* gstate__stringPath(gstateObject* self, PyObject* args)
1316
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1089
{
1326
a20515e15c4d Added optional x and y to _stringPath
rgbecker
parents: 1323
diff changeset
  1090
	double	w, x=0, y=0, s;
1316
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1091
	char*	text;
1321
6a1f7686da39 Renamed stringPath to _stringPath and improved it
rgbecker
parents: 1316
diff changeset
  1092
	PyObject *P, *p;
1316
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1093
	ArtBpath	*path, *pp;
4508
5f79dd4e0cc8 add some fixes inspired by Marius Gedminas as a partial fix of bb issue #174
robin <robin@reportlab.com>
parents: 4458
diff changeset
  1094
	Py_ssize_t	textlen;
5f79dd4e0cc8 add some fixes inspired by Marius Gedminas as a partial fix of bb issue #174
robin <robin@reportlab.com>
parents: 4458
diff changeset
  1095
	int		i, c;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1096
	void	*font = self->font;
3985
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1097
	PyObject	*textObj, *obj0;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1098
#ifdef	RENDERPM_FT
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
  1099
	int				ft_font = self->ft_font;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1100
	Py_UNICODE		*utext;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1101
	_ft_outliner_user_t _ft_data;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1102
#endif
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1103
	if(!font){
3753
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
  1104
		PyErr_SetString(PyExc_ValueError, "_renderPM.gstate__stringPath: No font set!");
1316
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1105
		return NULL;
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1106
		}
3985
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1107
	if(!PyArg_ParseTuple(args,"O|dd:_stringPath", &textObj, &x, &y)) return NULL;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1108
#ifdef	RENDERPM_FT
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1109
	if(ft_font){
3985
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1110
		/*we need unicode*/
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1111
		if(PyUnicode_Check(textObj)){
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1112
			obj0 = textObj;
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1113
			}
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1114
		else if(PyBytes_Check(textObj)){
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1115
			text = PyBytes_AsString(textObj);
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1116
			textlen = PyBytes_GET_SIZE(textObj);
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1117
			obj0 = PyUnicode_DecodeUTF8(text, textlen,NULL);
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1118
			if(!obj0) return NULL;
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1119
			}
4042
6382a792db9e _renderPM.c: move some labels to safer positions
robin
parents: 3985
diff changeset
  1120
		else goto L0;
3985
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1121
		textlen = PyUnicode_GetSize(obj0);
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1122
		utext = PyUnicode_AsUnicode(obj0);
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1123
		_ft_data.pathMax = 0;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1124
		_ft_data.path = NULL;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1125
		}
3985
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1126
	else {
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1127
#endif
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1128
		/*we need bytes*/
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1129
		if(PyUnicode_Check(textObj)){
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1130
			obj0 = PyUnicode_AsUTF8String(textObj);
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1131
			if(!obj0) return NULL;
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1132
			}
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1133
		else if(PyBytes_Check(textObj)){
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1134
			obj0 = textObj;
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1135
			}
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1136
		else goto L0;
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1137
		text = PyBytes_AsString(obj0);
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1138
		textlen = PyBytes_GET_SIZE(obj0);
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1139
#ifdef	RENDERPM_FT
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1140
		}
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1141
#endif
1316
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1142
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1143
	s = self->fontSize/self->fontEMSize;
3985
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1144
	P = PyTuple_New(textlen);
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1145
	for(i=0;i<textlen;i++){
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1146
#ifdef	RENDERPM_FT
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1147
		if(ft_font){
2510
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
  1148
			c = utext[i];
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1149
			_ft_data.pathLen = 0;
2114
26c636b61f7f TTFONTS Render
rgbecker
parents: 2111
diff changeset
  1150
			path = _ft_get_glyph_outline((FT_Face)font,c,&_ft_data,&w);
2510
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
  1151
			if(!path){
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
  1152
				_ft_data.pathLen = 0;
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
  1153
				path = _ft_get_glyph_outline((FT_Face)font,0,&_ft_data,&w);
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
  1154
				}
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1155
			}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1156
		else{
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1157
#endif
1316
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1158
		c = text[i]&0xff;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1159
		path = gt1_get_glyph_outline((Gt1EncodedFont*)font, c, &w);	/*ascii encoding for the moment*/
2510
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
  1160
		if(!path){
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
  1161
			path = notdefPath;
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
  1162
			w = 761;
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
  1163
			}
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1164
#ifdef	RENDERPM_FT
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1165
		}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1166
#endif
1316
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1167
		if(path){
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1168
			pp = path;
1321
6a1f7686da39 Renamed stringPath to _stringPath and improved it
rgbecker
parents: 1316
diff changeset
  1169
			while(pp->code!=ART_END){
6a1f7686da39 Renamed stringPath to _stringPath and improved it
rgbecker
parents: 1316
diff changeset
  1170
				if(pp->code==ART_CURVETO){
6a1f7686da39 Renamed stringPath to _stringPath and improved it
rgbecker
parents: 1316
diff changeset
  1171
					pp->x1= pp->x1*s+x;
1326
a20515e15c4d Added optional x and y to _stringPath
rgbecker
parents: 1323
diff changeset
  1172
					pp->y1= pp->y1*s+y;
1321
6a1f7686da39 Renamed stringPath to _stringPath and improved it
rgbecker
parents: 1316
diff changeset
  1173
					pp->x2= pp->x2*s+x;
1326
a20515e15c4d Added optional x and y to _stringPath
rgbecker
parents: 1323
diff changeset
  1174
					pp->y2= pp->y2*s+y;
1321
6a1f7686da39 Renamed stringPath to _stringPath and improved it
rgbecker
parents: 1316
diff changeset
  1175
					}
6a1f7686da39 Renamed stringPath to _stringPath and improved it
rgbecker
parents: 1316
diff changeset
  1176
				pp->x3 = pp->x3*s+x;
1326
a20515e15c4d Added optional x and y to _stringPath
rgbecker
parents: 1323
diff changeset
  1177
				pp->y3 = pp->y3*s+y;
1321
6a1f7686da39 Renamed stringPath to _stringPath and improved it
rgbecker
parents: 1316
diff changeset
  1178
				pp++;
6a1f7686da39 Renamed stringPath to _stringPath and improved it
rgbecker
parents: 1316
diff changeset
  1179
				}
4508
5f79dd4e0cc8 add some fixes inspired by Marius Gedminas as a partial fix of bb issue #174
robin <robin@reportlab.com>
parents: 4458
diff changeset
  1180
			p = _get_gstatePath((int)(pp-path),path);
2114
26c636b61f7f TTFONTS Render
rgbecker
parents: 2111
diff changeset
  1181
#ifdef	RENDERPM_FT
2510
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
  1182
			if(!ft_font && path!=notdefPath)
2114
26c636b61f7f TTFONTS Render
rgbecker
parents: 2111
diff changeset
  1183
#endif
2110
cca387467c50 Fixed memory family problems
rgbecker
parents: 2108
diff changeset
  1184
			art_free(path);
1316
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1185
			}
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1186
		else {
2510
92a577832bf1 _renderPM.c: improve bad glyph handling
rgbecker
parents: 2416
diff changeset
  1187
			/*fprintf(stderr, "No glyph outline for code %d!\n", c);*/
1321
6a1f7686da39 Renamed stringPath to _stringPath and improved it
rgbecker
parents: 1316
diff changeset
  1188
			w = 1000;
1316
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1189
			Py_INCREF(Py_None);
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1190
			p = Py_None;
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1191
			}
1321
6a1f7686da39 Renamed stringPath to _stringPath and improved it
rgbecker
parents: 1316
diff changeset
  1192
		PyTuple_SET_ITEM(P, i, p);
6a1f7686da39 Renamed stringPath to _stringPath and improved it
rgbecker
parents: 1316
diff changeset
  1193
		x += w*s;
1316
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1194
		}
3985
37fd6d44525a _renderPM.c: fix _stringPath & drawString argument handling
robin
parents: 3775
diff changeset
  1195
	if(textObj!=obj0) Py_DECREF(obj0);
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1196
#ifdef	RENDERPM_FT
2114
26c636b61f7f TTFONTS Render
rgbecker
parents: 2111
diff changeset
  1197
	if(ft_font) art_free(_ft_data.path);
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1198
#endif
1316
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1199
	return P;
4042
6382a792db9e _renderPM.c: move some labels to safer positions
robin
parents: 3985
diff changeset
  1200
6382a792db9e _renderPM.c: move some labels to safer positions
robin
parents: 3985
diff changeset
  1201
L0:	PyErr_SetString(PyExc_ValueError, "_renderPM.gstate_drawString: text must be bytes/unicode!");
6382a792db9e _renderPM.c: move some labels to safer positions
robin
parents: 3985
diff changeset
  1202
	return NULL;
1316
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1203
}
7b60e9a36437 Added stringPath
rgbecker
parents: 1313
diff changeset
  1204
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1205
static PyObject* gstate_setFont(gstateObject* self, PyObject* args)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1206
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1207
	char	*fontName;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1208
	Gt1EncodedFont*	f;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1209
	double	fontSize, fontEMSize;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1210
	int		ft_font;
3765
a7e7cd6e0003 renderPM.py now works to produce a pmout at least
robin
parents: 3753
diff changeset
  1211
	PyObject *fontNameObj,*b=NULL;
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1212
2760
0658253b1e8a _renderPM.c: fix up fontName attribute handling so it does the right thing
rgbecker
parents: 2738
diff changeset
  1213
	if(!PyArg_ParseTuple(args,"Od:setFont", &fontNameObj, &fontSize)) return NULL;
3765
a7e7cd6e0003 renderPM.py now works to produce a pmout at least
robin
parents: 3753
diff changeset
  1214
	if(PyUnicode_Check(fontNameObj)){
a7e7cd6e0003 renderPM.py now works to produce a pmout at least
robin
parents: 3753
diff changeset
  1215
		b=PyUnicode_AsUTF8String(fontNameObj);
4640
626937a80b64 cosmetic changes and add gstate setattr for fontSize
robin
parents: 4635
diff changeset
  1216
		if(!b){
626937a80b64 cosmetic changes and add gstate setattr for fontSize
robin
parents: 4635
diff changeset
  1217
			PyErr_SetString(PyExc_ValueError, "_renderPM.gstate_setFont: bytes conversion of fontName failed");
626937a80b64 cosmetic changes and add gstate setattr for fontSize
robin
parents: 4635
diff changeset
  1218
			goto err;
626937a80b64 cosmetic changes and add gstate setattr for fontSize
robin
parents: 4635
diff changeset
  1219
			}
3765
a7e7cd6e0003 renderPM.py now works to produce a pmout at least
robin
parents: 3753
diff changeset
  1220
		fontName = PyBytes_AsString(b);
a7e7cd6e0003 renderPM.py now works to produce a pmout at least
robin
parents: 3753
diff changeset
  1221
		}
a7e7cd6e0003 renderPM.py now works to produce a pmout at least
robin
parents: 3753
diff changeset
  1222
	else{
a7e7cd6e0003 renderPM.py now works to produce a pmout at least
robin
parents: 3753
diff changeset
  1223
		fontName = PyBytes_AsString(fontNameObj);
a7e7cd6e0003 renderPM.py now works to produce a pmout at least
robin
parents: 3753
diff changeset
  1224
		}
2760
0658253b1e8a _renderPM.c: fix up fontName attribute handling so it does the right thing
rgbecker
parents: 2738
diff changeset
  1225
	if(!fontName){
3753
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
  1226
		PyErr_SetString(PyExc_ValueError, "_renderPM.gstate_setFont: Invalid fontName");
3765
a7e7cd6e0003 renderPM.py now works to produce a pmout at least
robin
parents: 3753
diff changeset
  1227
		goto err;
2760
0658253b1e8a _renderPM.c: fix up fontName attribute handling so it does the right thing
rgbecker
parents: 2738
diff changeset
  1228
		}
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1229
	if(fontSize<0){
3753
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
  1230
		PyErr_SetString(PyExc_ValueError, "_renderPM.gstate_setFont: Invalid fontSize");
3765
a7e7cd6e0003 renderPM.py now works to produce a pmout at least
robin
parents: 3753
diff changeset
  1231
		goto err;
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1232
		}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1233
	f=gt1_get_encoded_font(fontName);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1234
	if(f){
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1235
		fontEMSize = 1000.;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1236
		ft_font = 0;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1237
		}
4640
626937a80b64 cosmetic changes and add gstate setattr for fontSize
robin
parents: 4635
diff changeset
  1238
#ifdef RENDERPM_FT
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1239
	else{
2108
87e6af640f37 Now compiles&links cleanly
rgbecker
parents: 2097
diff changeset
  1240
		f = (Gt1EncodedFont*)_ft_get_face(fontName);
2114
26c636b61f7f TTFONTS Render
rgbecker
parents: 2111
diff changeset
  1241
		fontEMSize = f ? ((FT_Face)f)->units_per_EM : 0;
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1242
		ft_font = 1;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1243
		}
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1244
#endif
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1245
	if(f){
3767
fa65fe72b6c2 py33: renderPM.c: attempt to remove memory leak
robin
parents: 3765
diff changeset
  1246
		Py_XDECREF(b);
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1247
		self->font = f;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1248
		self->fontSize = fontSize;
2760
0658253b1e8a _renderPM.c: fix up fontName attribute handling so it does the right thing
rgbecker
parents: 2738
diff changeset
  1249
		if(self->fontNameObj) Py_DECREF(self->fontNameObj);
0658253b1e8a _renderPM.c: fix up fontName attribute handling so it does the right thing
rgbecker
parents: 2738
diff changeset
  1250
		self->fontNameObj = fontNameObj;
0658253b1e8a _renderPM.c: fix up fontName attribute handling so it does the right thing
rgbecker
parents: 2738
diff changeset
  1251
		Py_INCREF(fontNameObj);
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1252
		self->fontEMSize = fontEMSize;
4640
626937a80b64 cosmetic changes and add gstate setattr for fontSize
robin
parents: 4635
diff changeset
  1253
#ifdef RENDERPM_FT
2097
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1254
		self->ft_font = ft_font;
47a369d004c3 Added in preliminary FT support
rgbecker
parents: 2042
diff changeset
  1255
#endif
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1256
		Py_INCREF(Py_None);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1257
		return Py_None;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1258
		}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1259
3753
251e8a89153d _renderPM.c: restore changes lost during branch grafting
robin
parents: 3542
diff changeset
  1260
	PyErr_SetString(PyExc_ValueError, "_renderPM.gstate_setFont: Can't find font!");
3765
a7e7cd6e0003 renderPM.py now works to produce a pmout at least
robin
parents: 3753
diff changeset
  1261
err:
a7e7cd6e0003 renderPM.py now works to produce a pmout at least
robin
parents: 3753
diff changeset
  1262
	Py_XDECREF(b);
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1263
	return NULL;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1264
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1265
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1266
static	void _dashFree(gstateObject* self)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1267
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1268
	if(self->dash.dash){
2110
cca387467c50 Fixed memory family problems
rgbecker
parents: 2108
diff changeset
  1269
		art_free(self->dash.dash);
898
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1270
		self->dash.dash = NULL;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1271
		}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1272
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1273
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1274
static	PyObject* _getA2DMX(double* ctm)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1275
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1276
	return Py_BuildValue("(dddddd)",ctm[0],ctm[1],ctm[2],ctm[3],ctm[4],ctm[5]);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1277
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1278
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1279
static int _setA2DMX(PyObject* value, double* ctm)
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1280
{
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1281
	int		i;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1282
	A2DMX	m;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1283
	if(value==Py_None){
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1284
		ctm[0] = ctm[3] = 1;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1285
		ctm[1] = ctm[2] = ctm[4] = ctm[5] = 0;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1286
		return 1;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1287
		}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1288
	if(!(i=PyArg_Parse(value,"(dddddd)",m+0,m+1,m+2,m+3,m+4,m+5))){
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1289
		PyErr_Clear();
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1290
		i=PyArg_Parse(value,"[dddddd]",m+0,m+1,m+2,m+3,m+4,m+5);
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1291
		}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1292
	if(i){
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1293
		ctm[0] = m[0];
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1294
		ctm[1] = m[1];
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1295
		ctm[2] = m[2];
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1296
		ctm[3] = m[3];
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1297
		ctm[4] = m[4];
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1298
		ctm[5] = m[5];
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1299
		}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1300
	return i;
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1301
}
4f12d1155790 Initial revision
rgbecker
parents:
diff changeset
  1302
1681
129ddacd8869 Rendering fixes & changes for Dinu's image shape
rgbecker
parents: 1676
diff changeset
  1303
#if 0
129ddacd8869 Rendering fixes & changes for Dinu's image shape
rgbecker
parents: 1676
diff changeset
  1304
static	void _reverse_rows_inplace( char *buf, int nrows, int stride)
129ddacd8869 Rendering fixes & changes for Dinu's image shape
rgbecker
parents: 1676
diff changeset
  1305
{