mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-01 00:17:27 +03:00 
			
		
		
		
	update Py_UNICODE to Py_UCS4
This commit is contained in:
		
							parent
							
								
									ea570a8c5b
								
							
						
					
					
						commit
						6aba1df727
					
				|  | @ -326,6 +326,7 @@ getfont(PyObject* self_, PyObject* args, PyObject* kw) | ||||||
| static int | static int | ||||||
| font_getchar(PyObject* string, int index, FT_ULong* char_out) | font_getchar(PyObject* string, int index, FT_ULong* char_out) | ||||||
| { | { | ||||||
|  | #if PY_VERSION_HEX < 0x03000000 | ||||||
|     if (PyUnicode_Check(string)) { |     if (PyUnicode_Check(string)) { | ||||||
|         Py_UNICODE* p = PyUnicode_AS_UNICODE(string); |         Py_UNICODE* p = PyUnicode_AS_UNICODE(string); | ||||||
|         int size = PyUnicode_GET_SIZE(string); |         int size = PyUnicode_GET_SIZE(string); | ||||||
|  | @ -335,7 +336,6 @@ font_getchar(PyObject* string, int index, FT_ULong* char_out) | ||||||
|         return 1; |         return 1; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| #if PY_VERSION_HEX < 0x03000000 |  | ||||||
|     if (PyString_Check(string)) { |     if (PyString_Check(string)) { | ||||||
|         unsigned char* p = (unsigned char*) PyString_AS_STRING(string); |         unsigned char* p = (unsigned char*) PyString_AS_STRING(string); | ||||||
|         int size = PyString_GET_SIZE(string); |         int size = PyString_GET_SIZE(string); | ||||||
|  | @ -344,6 +344,13 @@ font_getchar(PyObject* string, int index, FT_ULong* char_out) | ||||||
|         *char_out = (unsigned char) p[index]; |         *char_out = (unsigned char) p[index]; | ||||||
|         return 1; |         return 1; | ||||||
|     } |     } | ||||||
|  | #else | ||||||
|  |     if (PyUnicode_Check(string)) { | ||||||
|  |         if (index >= PyUnicode_GetLength(string)) | ||||||
|  |             return 0; | ||||||
|  |         *char_out = PyUnicode_ReadChar(string, index); | ||||||
|  |         return 1; | ||||||
|  |     } | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|     return 0; |     return 0; | ||||||
|  | @ -365,6 +372,7 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir, PyObject * | ||||||
|         goto failed; |         goto failed; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | #if PY_VERSION_HEX < 0x03000000 | ||||||
|     if (PyUnicode_Check(string)) { |     if (PyUnicode_Check(string)) { | ||||||
|         Py_UNICODE *text = PyUnicode_AS_UNICODE(string); |         Py_UNICODE *text = PyUnicode_AS_UNICODE(string); | ||||||
|         Py_ssize_t size = PyUnicode_GET_SIZE(string); |         Py_ssize_t size = PyUnicode_GET_SIZE(string); | ||||||
|  | @ -384,9 +392,7 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir, PyObject * | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|     } |     } else if (PyString_Check(string)) { | ||||||
| #if PY_VERSION_HEX < 0x03000000 |  | ||||||
|     else if (PyString_Check(string)) { |  | ||||||
|         char *text = PyString_AS_STRING(string); |         char *text = PyString_AS_STRING(string); | ||||||
|         int size = PyString_GET_SIZE(string); |         int size = PyString_GET_SIZE(string); | ||||||
|         if (! size) { |         if (! size) { | ||||||
|  | @ -403,6 +409,28 @@ text_layout_raqm(PyObject* string, FontObject* self, const char* dir, PyObject * | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | #else | ||||||
|  |     if (PyUnicode_Check(string)) { | ||||||
|  |         Py_UCS4 *text = PyUnicode_AsUCS4Copy(string); | ||||||
|  |         Py_ssize_t size = PyUnicode_GetLength(string); | ||||||
|  |         if (!text || !size) { | ||||||
|  |             /* return 0 and clean up, no glyphs==no size,
 | ||||||
|  |                and raqm fails with empty strings */ | ||||||
|  |             goto failed; | ||||||
|  |         } | ||||||
|  |         int set_text = (*p_raqm.set_text)(rq, (const uint32_t *)(text), size); | ||||||
|  |         PyMem_Free(text); | ||||||
|  |         if (!set_text) { | ||||||
|  |             PyErr_SetString(PyExc_ValueError, "raqm_set_text() failed"); | ||||||
|  |             goto failed; | ||||||
|  |         } | ||||||
|  |         if (lang) { | ||||||
|  |             if (!(*p_raqm.set_language)(rq, lang, start, size)) { | ||||||
|  |                 PyErr_SetString(PyExc_ValueError, "raqm_set_language() failed"); | ||||||
|  |                 goto failed; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
| #endif | #endif | ||||||
|     else { |     else { | ||||||
|         PyErr_SetString(PyExc_TypeError, "expected string"); |         PyErr_SetString(PyExc_TypeError, "expected string"); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user