B4A Library [B4X] BCTextEngine / BBCodeView - Text engine + BBCode parser + Rich Text View

Status
Not open for further replies.

peacemaker

Expert
Licensed User
Longtime User
Thanks, indeed, there is difference, but, seems, not each is able to detect. I remember that this "eye feature" may get negative result, if an app development customer needs such design nuances and is able to see, but me, as developer, - not
 

js486dog

Active Member
Licensed User
Longtime User
v1.73 released with support for kerning.

Without kerning:



With kerning:

Erel please I have a little problem with 1.73 version.

Please look at the pictures.
1.73

1.72

I load UTF8 text file in the BCTextEngine.
Here is my code:
B4X:
TView.TextEngine.WordBoundaries = "&*+-/<>=\' :{}" & TAB & CRLF & Chr(13)
If pis_nt.Text ="N" Then TView.Text = $" [Alignment=${alig}][TextSize=${txtsize}][color=${texcolor}][PLAIN]${te1}[/PLAIN][/color][/TextSize][/alignment] "$ _
Else TView.Text = $" [Alignment=${alig}][TextSize=${txtsize}][color=${texcolor}][b][PLAIN]${te1}[/PLAIN][/b][/color][/TextSize][/alignment] "$
 

Attachments

  • BCTextEngine_173.jpg
    193.8 KB · Views: 314
  • BCTextEngine_172.jpg
    192.2 KB · Views: 327
Last edited:

Toky Olivier

Active Member
Licensed User
Longtime User
It seems that the problem comes from some punctuations only: ! . "
 

William Lancee

Well-Known Member
Licensed User
Longtime User
@js486dog

Those word boundaries work fine in my app. So it must have something to do with your content "te1".
I added tabs and crlfs to my content and it still works fine. Are there any unprintable characters between "." and "Beda"?
 

William Lancee

Well-Known Member
Licensed User
Longtime User
I note that your boundary list is almost the same as the default (you have removed the . and the ,)
Does it work with the default (i.e. comment out: 'TView.TextEngine.WordBoundaries = "&*+-/<>=\' :{}" & TAB & CRLF & Chr(13)
Does your content have Chr(13) in it, as part of end of line characters?
Just thinking...

@Toky Olivier notes that the "!" is not in the word boundaries (either in yours or the default, neither is "?")
 
Last edited:

Toky Olivier

Active Member
Licensed User
Longtime User
I think that he needs to add also the Double Quote character in the WordBoundaries by adding Chr(34) or $"""$
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm curious, can you comment on how difficult this was to add?
Finding the kerning (?) space is not too difficult as it is based on the same implementation that used to extract the glyphs with the canvas:
B4X:
Private Sub GetKernSpaceBetweenChars (fm As BCFontMetrics, PrevChar As String, ThisChar As String, PrevGlyph As BCGlyph, ThisGlyph As BCGlyph) As Int
    Dim together As String = PrevChar & ThisChar
    Dim Space As Int = fm.KerningTable.GetDefault(together, -1000)
    If Space > -1000 Then Return Space
    Dim w As Int = CreateGlyph(together, fm, True).Width
    Dim res As Int = w - PrevGlyph.Width - ThisGlyph.Width
    fm.KerningTable.Put(together, res)
    Return res
End Sub

BCTextEngine is quite complex so any new feature and especially a low level feature such as this one, do require some work.
 

Sandman

Expert
Licensed User
Longtime User
BCTextEngine is quite complex so any new feature and especially a low level feature such as this one, do require some work.
I can imagine. I really appreciate it, thanks.

Thanks for the explanation.
 

dobro

Member
Licensed User
hello

I wanted to put an HTML text in the BBLabel
or BBCodeView, but it's causing an error.

while the display of a single line of text works

e.g. this works: sortie.Text = "[ b]BB code written in Bold [ /b]"

but not sortie.Text =HTML_code <--- variable filled with an HTML text

(Look my ZIP ) Thanks




Translated with www.DeepL.com/Translator (free version)
 

Attachments

  • lire_html_url.zip
    10.1 KB · Views: 360
Last edited:

dobro

Member
Licensed User
This library is not for HTML texts but for BB Codes.
You can use another library like: https://www.b4x.com/android/forum/threads/html-textview-v1-0.50696/#content

I understand that, yes.
but I thought I'd use the View to simply display the text of the HTML code, with no desire to interpret it ...

I'm looking for a view to simply display text
if in addition I can add tags to change the look ....

But thank you for your answer, I'll look at the library you recommend.

REEDIT :
Ps: the library that you indicate, seems to interpret the HTML code, it's not what I'm looking for.
I'm only looking for a "Gadget_Text" (rtf for example )
 

William Lancee

Well-Known Member
Licensed User
Longtime User
@dobro

If you don't want content to be parsed, use Plain tag. You have a "[" at index 916.

I don't know what the limit is, but 85108 for this string is too big on my system.

B4X:
Dim lengthLimit As Int = 2000
BBLabel1.Text = $"[Plain]${HTML_text.SubString2(0, lengthLimit)}[/Plain]"$
 
Last edited:

William Lancee

Well-Known Member
Licensed User
Longtime User
Oddly enough the Plain tag also works on this Forum! It exists between "use" and "tag" without quotes. The code tags are ignored!

If you don't want content to be parsed, use tag. You have a "[" at index 916.

I don't know what the limit is, but 85108 for this string is too big on my system.

[CODE=b4x]Dim lengthLimit As Int = 2000
BBLabel1.Text = $"[Plain]${HTML_text.SubString2(0, lengthLimit)}"$[/CODE]
 

dobro

Member
Licensed User
I answer to myself

That's what EditText is for !

@William Lancee

Thanks, I didn't know [plain ]
with the EditText, I can do what I want

it takes the size without any problem (on my tablet)
I also learned that ".initialize" was only useful
when the View (Gadget) is not already created by the designer

in any case thank you for everything
 
Last edited:

William Lancee

Well-Known Member
Licensed User
Longtime User
@js486dog

Your text sometimes has chr(160) instead of chr(32)
chr(160) Unicode is "NO-BREAK SPACE"
Replacing it with chr(32) fixes the problem.

B4X:
MyText = MyText.Replace (Chr(160), Chr(32))
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…