Re: multiple line
Behnam Esfahbod <[email protected]> Mon, 18 Sep 2017 09:45:55 -0700
| Newsgroups | gmane.comp.internationalization.fribidi |
|---|---|
| Message-ID | <CAPTpOHLsWk284wTR51jT7fUAkPEmkXvU8WE6-v2-VgOvnE2BXQ@mail.gmail.com> |
--===============1165637204== Content-Type: multipart/alternative; boundary="001a113fb81c2c537e0559797bdb" --001a113fb81c2c537e0559797bdb Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Yuri, The `fribidi_get_par_embedding_levels()`, as the name suggests, is expected to be called for each paragraph. IIRC, FriBidi doesn't have a high-level API to pass-in multi-paragraph text with a default paragraph direction to apply for all of them. This is something you need to do in your app. To answer your question about the example: the `fribidi_get_par_embedding_levels()` call is applying the default parag-dir only to the first paragraph, resulting in the first paragraph to jump to level 2. The other two paragraphs, though, are only processed with a default (0, LTR) parag-dir, which results in them remaining in 0 level. So, I believe what you need is to, after `fribidi_get_bidi_types()`, which can be done over multi-paragraph text, split your text into paragraph ranges, and call `fribidi_get_par_embedding_levels()` on each paragraph. Hope this answers your questions. -Behnam On Mon, Sep 18, 2017 at 4:24 AM, Yuri D. <[email protected]> wrote: > Hi, > > I wonder what is the correct input to the FRIBIDI library while parsing > the levels for multiple lines? > Should I send each line separately or I can send all the lines in the sam= e > string? > > I'm running the code below: > > FriBidiChar* unicodeString =3D new FriBidiChar[textLength]; > FriBidiCharType* bidiTypes =3D new FriBidiCharType[textLength]; > FriBidiLevel* bidiLevels =3D new FriBidiLevel[textLength]; > > std::string text =3D "some.\ncar.\nhere."; > > // Convert string to unicode > FriBidiStrIndex len =3D fribidi_charset_to_unicode(FRIBIDI_CHAR_SET_UTF8, > text.c_str(), (FriBidiStrIndex)text.length(), unicodeString); > > // Get BIDI types > fribidi_get_bidi_types(unicodeString, (uint32_t)text.size(), bidiTypes); > > // Get BIDI levels > FriBidiLevel resolveParDir =3D fribidi_get_par_embedding_levels(bidiTypes= , > (uint32_t)text.size(), *FRIBIDI_PAR_RTL*, bidiLevels); > > And in the result, I get the BIDI levels below: > 2 2 2 2 1 1 0 0 0 0 1 0 0 0 0 0 > > The question is: why I have a level change for the first '.' but not for > the following '.'? > > _______________________________________________ > fribidi mailing list > [email protected] > https://lists.freedesktop.org/mailman/listinfo/fribidi > > --=20 Behnam Esfahbod | =D8=A8=D9=87=D9=86=D8=A7=D9=85 =D8=A7=D8=B3=D9=81=D9=87= =D8=A8=D8=AF http://behnam.es/ GPG-FP: 3E7F B4B6 6F4C A8AB 9BB9 7520 5701 CA40 259E 0F8B --001a113fb81c2c537e0559797bdb Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Yuri,<div><br></div><div>The `<span style=3D"color:rgb(36,= 41,46);font-family:-apple-system,system-ui,"Segoe UI",Helvetica,A= rial,sans-serif,"Apple Color Emoji","Segoe UI Emoji",&q= uot;Segoe UI Symbol";font-size:14px">fribidi_get_par_embedding_</span>= <wbr style=3D"color:rgb(36,41,46);font-family:-apple-system,system-ui,"= ;Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji",&q= uot;Segoe UI Emoji","Segoe UI Symbol";font-size:14px"><span = style=3D"color:rgb(36,41,46);font-family:-apple-system,system-ui,"Sego= e UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","S= egoe UI Emoji","Segoe UI Symbol";font-size:14px">levels()`, = as the name suggests, is expected to be called for each paragraph. IIRC, Fr= iBidi doesn't have a high-level API to pass-in multi-paragraph text wit= h a default paragraph direction to apply for all of them. This is something= you need to do in your app.</span></div><div><span style=3D"color:rgb(36,4= 1,46);font-family:-apple-system,system-ui,"Segoe UI",Helvetica,Ar= ial,sans-serif,"Apple Color Emoji","Segoe UI Emoji",&qu= ot;Segoe UI Symbol";font-size:14px"><br></span></div><div><span style= =3D"color:rgb(36,41,46);font-family:-apple-system,system-ui,"Segoe UI&= quot;,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe = UI Emoji","Segoe UI Symbol";font-size:14px">To answer your q= uestion about the example: the `</span><span style=3D"color:rgb(36,41,46);f= ont-family:-apple-system,system-ui,"Segoe UI",Helvetica,Arial,san= s-serif,"Apple Color Emoji","Segoe UI Emoji","Sego= e UI Symbol";font-size:14px">fribidi_get_par_embedding_</span><wbr sty= le=3D"color:rgb(36,41,46);font-family:-apple-system,system-ui,"Segoe U= I",Helvetica,Arial,sans-serif,"Apple Color Emoji","Sego= e UI Emoji","Segoe UI Symbol";font-size:14px"><span style=3D= "color:rgb(36,41,46);font-family:-apple-system,system-ui,"Segoe UI&quo= t;,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI = Emoji","Segoe UI Symbol";font-size:14px">levels()` call is a= pplying the default parag-dir only to the first paragraph, resulting in the= first paragraph to jump to level 2. The other two paragraphs, though, are = only processed with a default (0, LTR) parag-dir, which results in them rem= aining in 0 level.</span></div><div><span style=3D"color:rgb(36,41,46);font= -family:-apple-system,system-ui,"Segoe UI",Helvetica,Arial,sans-s= erif,"Apple Color Emoji","Segoe UI Emoji","Segoe U= I Symbol";font-size:14px"><br></span></div><div><font color=3D"#24292e= " face=3D"-apple-system, system-ui, Segoe UI, Helvetica, Arial, sans-serif,= Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol"><span style=3D"font-si= ze:14px">So, I believe what you need is to, after `</span></font><span styl= e=3D"color:rgb(36,41,46);font-family:-apple-system,system-ui,"Segoe UI= ",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe= UI Emoji","Segoe UI Symbol";font-size:14px">fribidi_get_bid= i_types()`, which can be done over multi-paragraph text, split your text in= to paragraph ranges, and call `</span><span style=3D"color:rgb(36,41,46);fo= nt-family:-apple-system,system-ui,"Segoe UI",Helvetica,Arial,sans= -serif,"Apple Color Emoji","Segoe UI Emoji","Segoe= UI Symbol";font-size:14px">fribidi_get_par_embedding_</span><wbr styl= e=3D"color:rgb(36,41,46);font-family:-apple-system,system-ui,"Segoe UI= ",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe= UI Emoji","Segoe UI Symbol";font-size:14px"><span style=3D"= color:rgb(36,41,46);font-family:-apple-system,system-ui,"Segoe UI"= ;,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI E= moji","Segoe UI Symbol";font-size:14px">levels()` on each pa= ragraph.</span></div><div><span style=3D"color:rgb(36,41,46);font-family:-a= pple-system,system-ui,"Segoe UI",Helvetica,Arial,sans-serif,"= ;Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol&q= uot;;font-size:14px"><br></span></div><div><span style=3D"color:rgb(36,41,4= 6);font-family:-apple-system,system-ui,"Segoe UI",Helvetica,Arial= ,sans-serif,"Apple Color Emoji","Segoe UI Emoji","= Segoe UI Symbol";font-size:14px">Hope this answers your questions.</sp= an></div><div><span style=3D"color:rgb(36,41,46);font-family:-apple-system,= system-ui,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color= Emoji","Segoe UI Emoji","Segoe UI Symbol";font-si= ze:14px"><br></span></div><div><span style=3D"color:rgb(36,41,46);font-fami= ly:-apple-system,system-ui,"Segoe UI",Helvetica,Arial,sans-serif,= "Apple Color Emoji","Segoe UI Emoji","Segoe UI Sym= bol";font-size:14px">-Behnam</span></div><div><span style=3D"color:rgb= (36,41,46);font-family:-apple-system,system-ui,"Segoe UI",Helveti= ca,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"= ;,"Segoe UI Symbol";font-size:14px"><br></span></div><div><span s= tyle=3D"color:rgb(36,41,46);font-family:-apple-system,system-ui,"Segoe= UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Se= goe UI Emoji","Segoe UI Symbol";font-size:14px"><br></span><= /div></div><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Mon= , Sep 18, 2017 at 4:24 AM, Yuri D. <span dir=3D"ltr"><<a href=3D"mailto:= [email protected]" target=3D"_blank">[email protected]</a>></span> wrote= :<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-le= ft:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Hi,<div><br></div><div= >I wonder what is the correct input to the FRIBIDI library while parsing th= e levels for multiple lines?=C2=A0</div><div>Should I send each line separa= tely=C2=A0or I can send all the lines in the same string?=C2=A0</div><div><= br></div><div><p style=3D"box-sizing:border-box;margin-bottom:16px;color:rg= b(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI&quo= t;,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI = Emoji","Segoe UI Symbol";font-size:14px;margin-top:0px">I= 9;m running the code below:</p><p style=3D"box-sizing:border-box;margin-top= :0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,Blink= MacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple C= olor Emoji","Segoe UI Emoji","Segoe UI Symbol";fon= t-size:14px">FriBidiChar* unicodeString =3D new FriBidiChar[textLength];<br= style=3D"box-sizing:border-box">FriBidiCharType* bidiTypes =3D new FriBidi= CharType[textLength];<br style=3D"box-sizing:border-box">FriBidiLevel* bidi= Levels =3D new FriBidiLevel[textLength];</p><p style=3D"box-sizing:border-b= ox;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple= -system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,= "Apple Color Emoji","Segoe UI Emoji","Segoe UI Sym= bol";font-size:14px">std::string text =3D "some.\ncar.\nhere.&quo= t;;</p><p style=3D"box-sizing:border-box;margin-top:0px;margin-bottom:16px;= color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Sego= e UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","S= egoe UI Emoji","Segoe UI Symbol";font-size:14px">// Convert = string to unicode<br style=3D"box-sizing:border-box">FriBidiStrIndex len = =3D fribidi_charset_to_unicode(<wbr>FRIBIDI_CHAR_SET_UTF8, text.c_str(), (F= riBidiStrIndex)text.length()<wbr>, unicodeString);</p><p style=3D"box-sizin= g:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-fam= ily:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,s= ans-serif,"Apple Color Emoji","Segoe UI Emoji","Se= goe UI Symbol";font-size:14px">// Get BIDI types<br style=3D"box-sizin= g:border-box">fribidi_get_bidi_types(<wbr>unicodeString, (uint32_t)text.siz= e(), bidiTypes);</p><p style=3D"box-sizing:border-box;margin-top:0px;margin= -bottom:16px;color:rgb(36,41,46);font-family:-apple-system,BlinkMacSystemFo= nt,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji&= quot;,"Segoe UI Emoji","Segoe UI Symbol";font-size:14px= ">// Get BIDI levels<br style=3D"box-sizing:border-box">FriBidiLevel resolv= eParDir =3D fribidi_get_par_embedding_<wbr>levels(bidiTypes, (uint32_t)text= .size(), <b>FRIBIDI_PAR_RTL</b>, bidiLevels);</p><p style=3D"box-sizing:bor= der-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-= apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-s= erif,"Apple Color Emoji","Segoe UI Emoji","Segoe U= I Symbol";font-size:14px">And in the result, I get the BIDI levels bel= ow:<br style=3D"box-sizing:border-box">2 2 2 2 1 1 0 0 0 0 1 0 0 0 0 0</p><= p style=3D"box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rg= b(36,41,46);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI&quo= t;,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI = Emoji","Segoe UI Symbol";font-size:14px">The question is: wh= y I have a level change for the first '.' but not for the following= '.'?</p></div></div> <br>______________________________<wbr>_________________<br> fribidi mailing list<br> <a href=3D"mailto:[email protected]">[email protected].= org</a><br> <a href=3D"https://lists.freedesktop.org/mailman/listinfo/fribidi" rel=3D"n= oreferrer" target=3D"_blank">https://lists.freedesktop.org/<wbr>mailman/lis= tinfo/fribidi</a><br> <br></blockquote></div><br><br clear=3D"all"><div><br></div>-- <br><div cla= ss=3D"gmail_signature" data-smartmail=3D"gmail_signature"><div dir=3D"ltr">= Behnam Esfahbod |=C2=A0=D8=A8=D9=87=D9=86=D8=A7=D9=85 =D8=A7=D8=B3=D9=81=D9= =87=D8=A8=D8=AF<br><a href=3D"http://behnam.es/" target=3D"_blank">http://b= ehnam.es/</a><div><div>GPG-FP: 3E7F B4B6 6F4C A8AB 9BB9 7520 5701 CA40 259E= 0F8B<br></div></div><div><br></div></div></div> </div> --001a113fb81c2c537e0559797bdb-- --===============1165637204== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KZnJpYmlkaSBt YWlsaW5nIGxpc3QKZnJpYmlkaUBsaXN0cy5mcmVlZGVza3RvcC5vcmcKaHR0cHM6Ly9saXN0cy5m cmVlZGVza3RvcC5vcmcvbWFpbG1hbi9saXN0aW5mby9mcmliaWRpCg== --===============1165637204==--