summaryrefslogtreecommitdiff
path: root/bidi.h
blob: e1d1a4d39049a6b161763b42f55c51cddf11dc26 (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright (C) 2003 Mooffie <mooffie@typo.co.il>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.

#ifndef BDE_BIDI_H
#define BDE_BIDI_H

#include "types.h"

// The purpose of the BiDi class (and the public typdefs) is to make the
// interface of the actual BiDi engine (FriBiDi) hidden from the user. This
// BiDi class could be implemented using other engines, e.g. IBM's ICU.
//
// Ideally, The BiDi class would be an abstract class from which we derive
// class FriBiDi, class ICUBiDi etc. The configre script could then tell us
// which class to use based on what engine the system has.
//
// Note that we use very little of FriBiDi. We implement reordering ourselves
// (see the comments at EditBox::reorder()).

typedef FriBidiCharType	    ctype_t;
typedef FriBidiLevel	    level_t;
enum direction_t { dirLTR, dirRTL, dirN };
enum diralgo_t	 { algoUnicode, algoContextStrong, algoContextRTL, algoForceLTR, algoForceRTL };

#include "univalues.h"

class BiDi {

public:

    static bool mirror_char(unichar *ch) {
	return fribidi_get_mirror_char(*ch, ch);
    }

    static bool is_space(unichar ch) {
	return FRIBIDI_IS_SPACE(fribidi_get_type(ch)); 
    }

    static bool is_alnum(unichar ch) {
	ctype_t ctype = fribidi_get_type(ch);
	return FRIBIDI_IS_LETTER(ctype) || FRIBIDI_IS_NUMBER(ctype);
    }

    static bool is_nsm(unichar ch) {
	return fribidi_get_type(ch) == FRIBIDI_TYPE_NSM;
    }
    
    // is_wordch() returns what constitutes a word.
    static bool is_wordch(unichar ch) {
	return is_alnum(ch) || is_nsm(ch); 
    }
    
    static bool is_rtl(unichar ch) {
	return FRIBIDI_IS_RTL(fribidi_get_type(ch));
    }

    static bool is_explicit_mark(unichar ch)
    {
	return ch == UNI_LRM ||
	       ch == UNI_RLM ||
	       ch == UNI_LRE ||
	       ch == UNI_RLE ||
	       ch == UNI_PDF ||
	       ch == UNI_LRO ||
	       ch == UNI_RLO;
    }

    static bool is_transparent_formatting_code(unichar ch)
    {
	return is_explicit_mark(ch) ||
	       ch == UNI_ZWNJ ||
	       ch == UNI_ZWJ;
    }

    static bool is_hebrew_nsm(unichar ch)
    {
	return (ch >= UNI_HEB_ETNAHTA && ch <= UNI_HEB_UPPER_DOT
		    || ch == UNI_NS_UNDERSCORE)
		&& (ch != UNI_HEB_MAQAF &&
		    ch != UNI_HEB_PASEQ &&
		    ch != UNI_HEB_SOF_PASUQ);
    }

    static bool is_arabic_nsm(unichar ch)
    {
	return (ch >= UNI_ARA_FATHATAN && ch <= UNI_ARA_SUKUN
		    || ch == UNI_ARA_SUPERSCIPT_ALEF);
    }

    static bool is_cantillation_nsm(unichar ch)
    {
	return (ch >= UNI_HEB_ETNAHTA && ch <= UNI_HEB_MASORA_CIRCLE);
    }

    static void get_embedding_levels(unichar *str, idx_t len,
				     direction_t dir,
				     level_t *levels,
				     int line_breaks_count = 0,
				     idx_t *line_breaks = NULL,
				     bool disable_bidi = false);

    static direction_t determine_base_dir(unichar *str, idx_t len,
					  diralgo_t dir_algo);

    static void simple_log2vis(unistring &str, direction_t dir, unistring &dest);
};

#endif