File: renpybidicore.c

package info (click to toggle)
renpy 7.3.5+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 109,752 kB
  • sloc: python: 44,384; ansic: 5,113; makefile: 43; sh: 14
file content (44 lines) | stat: -rw-r--r-- 833 bytes parent folder | download | duplicates (2)
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
#include <Python.h>
#include <fribidi/fribidi.h>
#include <stdlib.h>

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


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


    Py_UNICODE *p = PyUnicode_AS_UNICODE(s);
    size = PyUnicode_GET_SIZE(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,
        direction,
        dstuni,
        NULL,
        NULL,
        NULL);

    rv = PyUnicode_FromUnicode(NULL, size);
    p = PyUnicode_AS_UNICODE(rv);

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

    return rv;
}