diff options
| author | Sam Varshavchik | 2021-02-14 16:18:38 -0500 |
|---|---|---|
| committer | Sam Varshavchik | 2021-02-14 16:18:38 -0500 |
| commit | f25a0880d0762e4d8a47cce13ab3cea1a1db01f8 (patch) | |
| tree | b2f23fe10adc2c941d282fecdf29c01d7dcdc560 /unicode | |
| parent | 688f31b2d1a5e0735661a829d7f743f9a0b68050 (diff) | |
| download | courier-libs-f25a0880d0762e4d8a47cce13ab3cea1a1db01f8.tar.bz2 | |
Return an indication of whether the paragraph embedding level was defaulted.
Diffstat (limited to 'unicode')
| -rw-r--r-- | unicode/ChangeLog | 7 | ||||
| -rw-r--r-- | unicode/biditest2.C | 6 | ||||
| -rw-r--r-- | unicode/book.xml | 54 | ||||
| -rw-r--r-- | unicode/courier-unicode.h.in | 30 | ||||
| -rw-r--r-- | unicode/unicode_bidi.c | 49 | ||||
| -rw-r--r-- | unicode/unicodecpp.C | 32 |
6 files changed, 126 insertions, 52 deletions
diff --git a/unicode/ChangeLog b/unicode/ChangeLog index 64f3f32..1995736 100644 --- a/unicode/ChangeLog +++ b/unicode/ChangeLog @@ -1,3 +1,10 @@ +2021-02-14 Sam Varshavchik <mrsam@courier-mta.com> + + * unicode_bidi_calc and unicode_bidi_calc_levels return a + unicode_bidi_direction object, to indicate whether the + computer paragraph embedding level was explicitly computed or + defaulted. + 2021-02-13 Sam Varshavchik <mrsam@courier-mta.com> * courier-unicode-version.m4: split version checking macro into its diff --git a/unicode/biditest2.C b/unicode/biditest2.C index d81a493..7787a33 100644 --- a/unicode/biditest2.C +++ b/unicode/biditest2.C @@ -204,14 +204,14 @@ void character_test() ? unicode::bidi_calc(s, direction) : unicode::bidi_calc(s); - if (std::get<1>(ret) != paragraph_embedding_level) + if (std::get<1>(ret).direction != paragraph_embedding_level) { std::cerr << "Regression, line " << linenum << ": expected " << paragraph_embedding_level << " paragraph embedding level, got " - << (int)std::get<1>(ret) + << (int)std::get<1>(ret).direction << std::endl; exit(1); } @@ -552,7 +552,7 @@ void null_character_test() s=U""; res=unicode::bidi_calc(s, UNICODE_BIDI_RL); - if (std::get<1>(res) != UNICODE_BIDI_RL) + if (std::get<1>(res).direction != UNICODE_BIDI_RL) { std::cerr << "Paragraph embedding level not honored" << std::endl; diff --git a/unicode/book.xml b/unicode/book.xml index 89e93f0..2a83033 100644 --- a/unicode/book.xml +++ b/unicode/book.xml @@ -359,7 +359,7 @@ make install DESTDIR=/tmp/courier-unicode-instimage # For example.</programlisti </funcprototype> <funcprototype> - <funcdef>void <function>unicode_bidi_calc_levels</function></funcdef> + <funcdef>struct unicode_bidi_direction <function>unicode_bidi_calc_levels</function></funcdef> <paramdef>const char32_t *<parameter>p</parameter></paramdef> <paramdef>const unicode_bidi_type_t *<parameter>types</parameter></paramdef> <paramdef>size_t <parameter>n</parameter></paramdef> @@ -368,7 +368,7 @@ make install DESTDIR=/tmp/courier-unicode-instimage # For example.</programlisti </funcprototype> <funcprototype> - <funcdef>void <function>unicode_bidi_calc</function></funcdef> + <funcdef>struct unicode_bidi_direction <function>unicode_bidi_calc</function></funcdef> <paramdef>const char32_t *<parameter>p</parameter></paramdef> <paramdef>size_t <parameter>n</parameter></paramdef> <paramdef>unicode_bidi_level_t *<parameter>levels</parameter></paramdef> @@ -645,8 +645,46 @@ make install DESTDIR=/tmp/courier-unicode-instimage # For example.</programlisti return the resolved paragraph direction level, which always matches the passed in level, if specified, else it - reports the - derived one. + reports the derived one. These functions return a + <structname>unicode_bidi_direction</structname> structure: + </para> + + <informaltable border='0'> + <tgroup cols="3"> + <colspec colname='c1' /> + <colspec colname='c2' /> + <colspec colname='c3' /> + <tbody> + <row> + <entry namest='c1' nameend='c3'>struct <structname>unicode_bidi_direction</structname> {</entry> + </row> + <row> + <entry></entry> + <entry>unicode_bidi_level_t</entry> + <entry><varname>direction</varname>;</entry> + </row> + <row> + <entry></entry> + <entry>int</entry> + <entry><varname>is_explicit</varname>;</entry> + </row> + <row> + <entry namest='c1' nameend='c3'>};</entry> + </row> + </tbody> + </tgroup> + </informaltable> + <para> + <varname>direction</varname> gives the paragraph embedding + level, <literal>UNICODE_BIDI_LR</literal> or + <literal> UNICODE_BIDI_RL</literal>. + <varname>is_explicit</varname> indicates whether: + the optional pointer to a + <literal>UNICODE_BIDI_LR</literal> or + <literal>UNICODE_BIDI_RL</literal> value was specified (and + returned in <varname>direction</varname>), or whether the + <varname>direction</varname> comes from an character with an + explicit direction indication. </para> <para> @@ -2899,12 +2937,12 @@ make install DESTDIR=/tmp/courier-unicode-instimage # For example.</programlisti <funcsynopsis> <funcprototype> - <funcdef>std::tuple<std::vector<unicode_bidi_level_t>, unicode_bidi_level_t> <function>unicode::bidi_calc</function></funcdef> + <funcdef>std::tuple<std::vector<unicode_bidi_level_t>, struct unicode_bidi_direction> <function>unicode::bidi_calc</function></funcdef> <paramdef>const unicode::bidi_calc_types &<parameter>ustring</parameter></paramdef> </funcprototype> <funcprototype> - <funcdef>std::tuple<std::vector<unicode_bidi_level_t>, unicode_bidi_level_t> <function>unicode::bidi_calc</function></funcdef> + <funcdef>std::tuple<std::vector<unicode_bidi_level_t>, struct unicode_bidi_direction> <function>unicode::bidi_calc</function></funcdef> <paramdef>const unicode::bidi_calc_types &<parameter>ustring</parameter></paramdef> <paramdef>unicode_bidi_level_t <parameter>embedding_level</parameter></paramdef> </funcprototype> @@ -3027,7 +3065,7 @@ make install DESTDIR=/tmp/courier-unicode-instimage # For example.</programlisti <programlisting><![CDATA[ std::u32string text; -auto [levels, level]=unicode::bidi_calc(text); +auto [levels, direction]=unicode::bidi_calc(text); ]]></programlisting> </informalexample> @@ -3050,7 +3088,7 @@ types.setbnl(text); // Optional // types.types is a std::vector of enum_bidi_types_t values -auto [levels, level]=unicode::bidi_calc(types); +auto [levels, direction]=unicode::bidi_calc(types); ]]></programlisting> </informalexample> diff --git a/unicode/courier-unicode.h.in b/unicode/courier-unicode.h.in index 38d9c37..e0a5b99 100644 --- a/unicode/courier-unicode.h.in +++ b/unicode/courier-unicode.h.in @@ -604,10 +604,10 @@ struct unicode_bidi_direction { struct unicode_bidi_direction unicode_bidi_get_direction(const char32_t *p, size_t n); -extern unicode_bidi_level_t unicode_bidi_calc(const char32_t *p, size_t n, - unicode_bidi_level_t *bufp, - const unicode_bidi_level_t * - initial_embedding_level); +struct unicode_bidi_direction unicode_bidi_calc(const char32_t *p, size_t n, + unicode_bidi_level_t *bufp, + const unicode_bidi_level_t * + initial_embedding_level); extern void unicode_bidi_reorder(char32_t *p, unicode_bidi_level_t *levels, @@ -652,13 +652,15 @@ extern void unicode_bidi_setbnl(char32_t *p, const enum_bidi_type_t *types, size_t n); -extern unicode_bidi_level_t unicode_bidi_calc_levels(const char32_t *p, - const enum_bidi_type_t - *types, - size_t n, - unicode_bidi_level_t *bufp, - const unicode_bidi_level_t - *initial_embedding_level); +extern struct unicode_bidi_direction +unicode_bidi_calc_levels(const char32_t *p, + const enum_bidi_type_t + *types, + size_t n, + unicode_bidi_level_t *bufp, + const unicode_bidi_level_t + *initial_embedding_level); + /* Bitmask options to unicode_bidi_cleanup */ /* @@ -2231,7 +2233,7 @@ struct bidi_calc_types { //! can be constructed explicitly, and then passed in directly. std::tuple<std::vector<unicode_bidi_level_t>, - unicode_bidi_level_t> bidi_calc(const bidi_calc_types &s); + struct unicode_bidi_direction> bidi_calc(const bidi_calc_types &s); //! Calculate bidirectional embedding levels @@ -2242,8 +2244,8 @@ std::tuple<std::vector<unicode_bidi_level_t>, //! embedding level. std::tuple<std::vector<unicode_bidi_level_t>, - unicode_bidi_level_t> bidi_calc(const bidi_calc_types &s, - unicode_bidi_level_t level); + struct unicode_bidi_direction> bidi_calc(const bidi_calc_types &s, + unicode_bidi_level_t level); //! Reorder bidirectional text diff --git a/unicode/unicode_bidi.c b/unicode/unicode_bidi.c index b23b833..b97ec25 100644 --- a/unicode/unicode_bidi.c +++ b/unicode/unicode_bidi.c @@ -464,7 +464,7 @@ struct directional_status_stack_entry { typedef struct { struct directional_status_stack_entry *head; - unicode_bidi_level_t paragraph_embedding_level; + struct unicode_bidi_direction paragraph_embedding_level; const char32_t *chars; enum_bidi_type_t *types; const enum_bidi_type_t *orig_types; @@ -618,7 +618,7 @@ get_enum_bidi_type_for_paragraph_embedding_level(size_t i, return p->p[i]; } -static unicode_bidi_level_t +static struct unicode_bidi_direction compute_paragraph_embedding_level_from_types(const enum_bidi_type_t *p, size_t i, size_t j) { @@ -628,7 +628,7 @@ compute_paragraph_embedding_level_from_types(const enum_bidi_type_t *p, return compute_paragraph_embedding_level (i, j, get_enum_bidi_type_for_paragraph_embedding_level, - &info).direction; + &info); } static directional_status_stack_t @@ -642,10 +642,18 @@ directional_status_stack_init(const char32_t *chars, stack=(directional_status_stack_t)calloc(1, sizeof(*stack)); - stack->paragraph_embedding_level= - initial_embedding_level - ? *initial_embedding_level & 1 - : compute_paragraph_embedding_level_from_types(types, 0, n); + if (initial_embedding_level) + { + stack->paragraph_embedding_level.direction= + *initial_embedding_level & 1; + stack->paragraph_embedding_level.is_explicit=1; + } + else + { + stack->paragraph_embedding_level= + compute_paragraph_embedding_level_from_types(types, + 0, n); + } stack->chars=chars; stack->orig_types=types; @@ -666,7 +674,8 @@ directional_status_stack_init(const char32_t *chars, stack->size=n; directional_status_stack_push(stack, - stack->paragraph_embedding_level, + stack->paragraph_embedding_level + .direction, do_neutral, 0); return stack; @@ -736,7 +745,7 @@ void unicode_bidi_setbnl(char32_t *p, } } -unicode_bidi_level_t +struct unicode_bidi_direction unicode_bidi_calc(const char32_t *p, size_t n, unicode_bidi_level_t *bufp, const unicode_bidi_level_t *initial_embedding_level) { @@ -748,7 +757,7 @@ unicode_bidi_calc(const char32_t *p, size_t n, unicode_bidi_level_t *bufp, unicode_bidi_calc_types(p, n, buf); - unicode_bidi_level_t level= + struct unicode_bidi_direction level= unicode_bidi_calc_levels(p, buf, n, @@ -762,7 +771,7 @@ unicode_bidi_calc(const char32_t *p, size_t n, unicode_bidi_level_t *bufp, static void unicode_bidi_cl(directional_status_stack_t stack); -unicode_bidi_level_t +struct unicode_bidi_direction unicode_bidi_calc_levels(const char32_t *p, const enum_bidi_type_t *types, size_t n, @@ -779,12 +788,12 @@ unicode_bidi_calc_levels(const char32_t *p, stack=directional_status_stack_init(p, types, n, bufp, initial_embedding_level); - unicode_bidi_level_t paragraph_embedding_level= + struct unicode_bidi_direction paragraph_embedding_level= stack->paragraph_embedding_level; #ifdef BIDI_DEBUG fprintf(DEBUGDUMP, "BIDI: START: Paragraph embedding level: %d\n", - (int)stack->paragraph_embedding_level); + (int)paragraph_embedding_level.direction); #endif unicode_bidi_cl(stack); @@ -971,7 +980,8 @@ static void unicode_bidi_cl(directional_status_stack_t stack) } cur_class=compute_paragraph_embedding_level_from_types - (stack->types, i+1, j) == 1 + (stack->types, i+1, j).direction + != UNICODE_BIDI_LR ? UNICODE_BIDI_TYPE_RLI : UNICODE_BIDI_TYPE_LRI; } @@ -1104,7 +1114,8 @@ static void unicode_bidi_cl(directional_status_stack_t stack) { /* X8 */ - stack->levels[i]=stack->paragraph_embedding_level; + stack->levels[i]= + stack->paragraph_embedding_level.direction; } } @@ -1203,9 +1214,9 @@ static void unicode_bidi_cl(directional_status_stack_t stack) continue; /* Edge case */ unicode_bidi_level_t before= - stack->paragraph_embedding_level; + stack->paragraph_embedding_level.direction; unicode_bidi_level_t after= - stack->paragraph_embedding_level; + stack->paragraph_embedding_level.direction; size_t first_i=beg_iter.i; @@ -1301,11 +1312,11 @@ static void unicode_bidi_cl(directional_status_stack_t stack) case UNICODE_BIDI_TYPE_PDI: if (seen_sb) stack->levels[i]= - stack->paragraph_embedding_level; + stack->paragraph_embedding_level.direction; break; case UNICODE_BIDI_TYPE_S: case UNICODE_BIDI_TYPE_B: - stack->levels[i]=stack->paragraph_embedding_level; + stack->levels[i]=stack->paragraph_embedding_level.direction; seen_sb=1; break; default: diff --git a/unicode/unicodecpp.C b/unicode/unicodecpp.C index 7038129..e91f756 100644 --- a/unicode/unicodecpp.C +++ b/unicode/unicodecpp.C @@ -581,18 +581,29 @@ void unicode::bidi_calc_types::setbnl(std::u32string &s) unicode_bidi_setbnl(&s[0], &types[0], s.size()); } -std::tuple<std::vector<unicode_bidi_level_t>, unicode_bidi_level_t> +std::tuple<std::vector<unicode_bidi_level_t>, + struct unicode_bidi_direction> unicode::bidi_calc(const bidi_calc_types &s) { return unicode::bidi_calc(s, UNICODE_BIDI_SKIP); } -std::tuple<std::vector<unicode_bidi_level_t>, unicode_bidi_level_t> +std::tuple<std::vector<unicode_bidi_level_t>, + struct unicode_bidi_direction> unicode::bidi_calc(const bidi_calc_types &st, unicode_bidi_level_t paragraph_embedding_level) { + std::tuple<std::vector<unicode_bidi_level_t>, + struct unicode_bidi_direction> + ret; + auto &direction_ret=std::get<1>(ret); + if (st.s.size() != st.types.size()) - return { {}, UNICODE_BIDI_LR }; + { + direction_ret.direction=UNICODE_BIDI_LR; + direction_ret.is_explicit=false; + return ret; + } const unicode_bidi_level_t *initial_embedding_level=0; @@ -602,12 +613,17 @@ unicode::bidi_calc(const bidi_calc_types &st, initial_embedding_level=¶graph_embedding_level; } - std::tuple<std::vector<unicode_bidi_level_t>, unicode_bidi_level_t> - ret; - std::get<0>(ret).resize(st.s.size()); - std::get<1>(ret)=initial_embedding_level ? - paragraph_embedding_level : UNICODE_BIDI_LR; + + if (initial_embedding_level) + { + direction_ret.direction=paragraph_embedding_level; + direction_ret.is_explicit=1; + } + else + { + direction_ret.direction= UNICODE_BIDI_LR; + } if (st.s.size()) { |
