File: renpybidicore.c

package info (click to toggle)
renpy 8.0.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 81,768 kB
  • sloc: python: 44,587; ansic: 13,708; javascript: 308; makefile: 41; sh: 13
file content (52 lines) | stat: -rw-r--r-- 977 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <Python.h>

#ifdef RENPY_BUILD
#include <fribidi.h>
#else
#include <fribidi-src/lib/fribidi.h>
#endif

#include <stdlib.h>

#ifndef alloca
#include <alloca.h>
#endif


PyObject *renpybidi_log2vis(PyObject *s, int *direction) {
    Py_ssize_t size;
    FriBidiChar *srcuni;
    FriBidiChar *dstuni;
    PyObject *rv;


    Py_UNICODE *p = PyUnicode_AS_UNICODE((PyUnicodeObject *) s);
    size = PyUnicode_GET_SIZE((PyUnicodeObject *) s);

    srcuni = (FriBidiChar *) alloca(size * 4);
    dstuni = (FriBidiChar *) alloca(size * 4);

    for (Py_ssize_t i = 0; i < size; i++) {
        srcuni[i] = p[i];
    }

    fribidi_log2vis(
        srcuni,
        size,
        (FriBidiParType *) direction,
        dstuni,
        NULL,
        NULL,
        NULL);


    p = (Py_UNICODE *) alloca(size * sizeof(Py_UNICODE));

    for (Py_ssize_t i = 0; i < size; i++) {
        p[i] = (Py_UNICODE) dstuni[i];
    }

    rv = PyUnicode_FromUnicode(p, size);

    return rv;
}