Aug 6, 2011 Replies: 121 This library contains RichString and RichStringBuilder objects. These objects are analogous to the normal String and StringBuilder. However RichStrings can contain formatting information that controls how they are drawn when used as the text in a View. This library also contains a RichStringFormatter object. This object, once suitably initialised, will efficiently format RichStrings passed to it. For long strings that require many changes of format this is much more efficient than using the individual RichString formatting commands. EDIT :- Version 1.1 posted. See post #8 for details. EDIT :- Version 1.2 posted including RichStringFormatter. See post #13 for details. EDIT :- Version 1.3 posted. See post #15 for details. EDIT :- Version 1.4 posted. See post #56 for details. EDIT (by Erel) :- Version 1.5: https://www.b4x.com/android/forum/threads/richstring-library.10680/page-6#post-475477 Attachments RichString.zip RichString.zip 11.6 KB · Views: 3,218 Last edited by a moderator: Jan 5, 2017 Click to expand...
This library contains RichString and RichStringBuilder objects. These objects are analogous to the normal String and StringBuilder. However RichStrings can contain formatting information that controls how they are drawn when used as the text in a View. This library also contains a RichStringFormatter object. This object, once suitably initialised, will efficiently format RichStrings passed to it. For long strings that require many changes of format this is much more efficient than using the individual RichString formatting commands. EDIT :- Version 1.1 posted. See post #8 for details. EDIT :- Version 1.2 posted including RichStringFormatter. See post #13 for details. EDIT :- Version 1.3 posted. See post #15 for details. EDIT :- Version 1.4 posted. See post #56 for details. EDIT (by Erel) :- Version 1.5: https://www.b4x.com/android/forum/threads/richstring-library.10680/page-6#post-475477
agraham Expert Licensed User Longtime User Aug 23, 2011 #21 corwin42 said: New version of RichString Library? Click to expand... Yeah! Sorry, it's a breaking change in an unissued version. Remove the second parameter for the issued version which uses a default value.
corwin42 said: New version of RichString Library? Click to expand... Yeah! Sorry, it's a breaking change in an unissued version. Remove the second parameter for the issued version which uses a default value.
corwin42 Expert Licensed User Longtime User Aug 23, 2011 #22 Ok, works. Thank you very much. You are the best :icon_clap:
B brainfart Member Licensed User Longtime User Sep 13, 2011 #23 Feature request. (If possible naturally):sign0147: Add method to load RTF (rich text format) file and pass the formatting to a multi-line label. I am trying to write a help file/user manual and embed it in my application. The easiest way to write and then maintain a user manual with bold headings, underlines and italics would be to use word editing tool and saving it to file, then adding it to resources in the app. I am trying to avoid using WebView because of INTERNET permission which turns off a lot of potential down-loaders before they read fine print from me explaining that I do not use their data plan. Thanks. Last edited: Sep 13, 2011
Feature request. (If possible naturally):sign0147: Add method to load RTF (rich text format) file and pass the formatting to a multi-line label. I am trying to write a help file/user manual and embed it in my application. The easiest way to write and then maintain a user manual with bold headings, underlines and italics would be to use word editing tool and saving it to file, then adding it to resources in the app. I am trying to avoid using WebView because of INTERNET permission which turns off a lot of potential down-loaders before they read fine print from me explaining that I do not use their data plan. Thanks.
agraham Expert Licensed User Longtime User Sep 13, 2011 #24 brainfart said: Add method to load RTF (rich text format) file and pass the formatting to a multi-line label. Click to expand... There's no point in putting that in a library, it could just as well be implemented in a Code module with no loss of performance and more flexibilty in being able to modify it. I leave the challenge of the implementation to you.
brainfart said: Add method to load RTF (rich text format) file and pass the formatting to a multi-line label. Click to expand... There's no point in putting that in a library, it could just as well be implemented in a Code module with no loss of performance and more flexibilty in being able to modify it. I leave the challenge of the implementation to you.
B brainfart Member Licensed User Longtime User Sep 13, 2011 #25 agraham said: ...... I leave the challenge of the implementation to you. Click to expand... :sign0148: Now my brain hurts. I will think about it.
agraham said: ...... I leave the challenge of the implementation to you. Click to expand... :sign0148: Now my brain hurts. I will think about it.
R reeZZer Member Licensed User Longtime User Dec 2, 2011 #26 Hello agraham, thank you very much for his excellent Library , my Chat has now COLORS :sign0060: But i see that this only works for Labels and EditText i think, would it be possible to change the color of a specific Text in a Listview? I show the Userlist over Liestview and would like to color specific names like this: rs.Initialize("{U}Username{U}") rs.Color2(Colors.Blue, "{U}") UserList.AddSingleLine(rs) but that don't work , any other format is the same result. Thank in advance ! Keep up the good work. greeTz, reeZZer
Hello agraham, thank you very much for his excellent Library , my Chat has now COLORS :sign0060: But i see that this only works for Labels and EditText i think, would it be possible to change the color of a specific Text in a Listview? I show the Userlist over Liestview and would like to color specific names like this: rs.Initialize("{U}Username{U}") rs.Color2(Colors.Blue, "{U}") UserList.AddSingleLine(rs) but that don't work , any other format is the same result. Thank in advance ! Keep up the good work. greeTz, reeZZer
quimacama Member Licensed User Longtime User Apr 20, 2012 #27 I can't show more than one superscript? I have this code Dim rs As RichString Dim rsb As RichStringBuilder rsb.Initialize rsb.Append ("(2{superscript}3{superscript}) ") rsb.Append ("(3{superscript}2{superscript}) ") rsb.Append ("(5{superscript}4{superscript}) ") rs.Initialize(rsb) rs.Superscript2( "{superscript}") label.Text= rs but the result in the label is (2³)*(3{superscript}2)*(54{superscript}) What can I do?
I can't show more than one superscript? I have this code Dim rs As RichString Dim rsb As RichStringBuilder rsb.Initialize rsb.Append ("(2{superscript}3{superscript}) ") rsb.Append ("(3{superscript}2{superscript}) ") rsb.Append ("(5{superscript}4{superscript}) ") rs.Initialize(rsb) rs.Superscript2( "{superscript}") label.Text= rs but the result in the label is (2³)*(3{superscript}2)*(54{superscript}) What can I do?
agraham Expert Licensed User Longtime User Apr 20, 2012 #28 Shorten your tokens . Code: Copy rsb.Initialize rsb.Append ("(2{SUP}3{SUP}) ") rsb.Append ("(3{SUP}2{SUP}) ") rsb.Append ("(5{SUP}4{SUP}) ") rs.Initialize(rsb) rs.Superscript2( "{SUP}") It is failing because you are superscripting a single character and the token recognition is failing. Longer superscripted sequences will work with longer tokens. Unfortunately I can't immediately see why this happens but it looks like the length of the token must be less than (length of the formatted span + 5)
Shorten your tokens . Code: Copy rsb.Initialize rsb.Append ("(2{SUP}3{SUP}) ") rsb.Append ("(3{SUP}2{SUP}) ") rsb.Append ("(5{SUP}4{SUP}) ") rs.Initialize(rsb) rs.Superscript2( "{SUP}") It is failing because you are superscripting a single character and the token recognition is failing. Longer superscripted sequences will work with longer tokens. Unfortunately I can't immediately see why this happens but it looks like the length of the token must be less than (length of the formatted span + 5)
peacemaker Expert Licensed User Longtime User Apr 21, 2012 #30 agraham said: There's no point in putting that in a library, it could just as well be implemented in a Code module with no loss of performance and more flexibilty in being able to modify it. I leave the challenge of the implementation to you. Click to expand... Does it mean to parse RTF file format, re-formatting loaded text by RichString lib line-by-line ... ?
agraham said: There's no point in putting that in a library, it could just as well be implemented in a Code module with no loss of performance and more flexibilty in being able to modify it. I leave the challenge of the implementation to you. Click to expand... Does it mean to parse RTF file format, re-formatting loaded text by RichString lib line-by-line ... ?
imgsimonebiliato Well-Known Member Licensed User Longtime User Jun 14, 2012 #31 Hi agraham, may thanks for your useful library. Please, can you help me? I want to set this code: rs.Initialize("{BI}{C}{U}COMMESSA{U}{C}{BI}") rs.Color2( Colors.Cyan, "{C}" ) rs.Underscore2("{U}") rs.Style2( rs.STYLE_BOLD, "{BI}" ) to other 10 label.text, changing "COMMESSA" with other. Who can I do, without re-write the same code all times?
Hi agraham, may thanks for your useful library. Please, can you help me? I want to set this code: rs.Initialize("{BI}{C}{U}COMMESSA{U}{C}{BI}") rs.Color2( Colors.Cyan, "{C}" ) rs.Underscore2("{U}") rs.Style2( rs.STYLE_BOLD, "{BI}" ) to other 10 label.text, changing "COMMESSA" with other. Who can I do, without re-write the same code all times?
Erel B4X founder Staff member Licensed User Longtime User Jun 14, 2012 #32 Something like: Code: Copy Sub CreateRS(Title As String) As RichString rs.Initialize("{BI}{C}{U}" & Title & "{U}{C}{BI}") rs.Color2( Colors.Cyan, "{C}" ) rs.Underscore2("{U}") rs.Style2( rs.STYLE_BOLD, "{BI}" ) return rs End Sub Label1.Text = CreateRS("COMMESSB")
Something like: Code: Copy Sub CreateRS(Title As String) As RichString rs.Initialize("{BI}{C}{U}" & Title & "{U}{C}{BI}") rs.Color2( Colors.Cyan, "{C}" ) rs.Underscore2("{U}") rs.Style2( rs.STYLE_BOLD, "{BI}" ) return rs End Sub Label1.Text = CreateRS("COMMESSB")
imgsimonebiliato Well-Known Member Licensed User Longtime User Jun 14, 2012 #33 Erel said: Something like: Code: Copy Sub CreateRS(Title As String) As RichString rs.Initialize("{BI}{C}{U}" & Title & "{U}{C}{BI}") rs.Color2( Colors.Cyan, "{C}" ) rs.Underscore2("{U}") rs.Style2( rs.STYLE_BOLD, "{BI}" ) return rs End Sub Label1.Text = CreateRS("COMMESSB") Click to expand... Hi Erel, like a function? I've just tried it, but without success
Erel said: Something like: Code: Copy Sub CreateRS(Title As String) As RichString rs.Initialize("{BI}{C}{U}" & Title & "{U}{C}{BI}") rs.Color2( Colors.Cyan, "{C}" ) rs.Underscore2("{U}") rs.Style2( rs.STYLE_BOLD, "{BI}" ) return rs End Sub Label1.Text = CreateRS("COMMESSB") Click to expand... Hi Erel, like a function? I've just tried it, but without success
Erel B4X founder Staff member Licensed User Longtime User Jun 14, 2012 #34 You should post the error message. Here it is simple, I forgot to Dim rs.
imgsimonebiliato Well-Known Member Licensed User Longtime User Jun 14, 2012 #35 I did it. Many thanks!!! :sign0188: :sign0098:
Discorez Member Licensed User Longtime User Aug 9, 2012 #36 Erel, it is possible to show the caret for colorized text, if RichString used with EditText?
Erel B4X founder Staff member Licensed User Longtime User Aug 10, 2012 #37 How do you want to use it with EditText?
Discorez Member Licensed User Longtime User Aug 10, 2012 #38 For example, as code editor with syntax highlighting, or display errors for check spelling. The Rich text also should "participate" in editing - the caret and selection color, copy/paste, e.t.c. It is possible to create better an independent class - RichEditText?
For example, as code editor with syntax highlighting, or display errors for check spelling. The Rich text also should "participate" in editing - the caret and selection color, copy/paste, e.t.c. It is possible to create better an independent class - RichEditText?
Erel B4X founder Staff member Licensed User Longtime User Aug 10, 2012 #39 I don't think that it is possible to use this library for building a code editor.
mjtaryan Active Member Licensed User Longtime User Aug 30, 2012 #40 More brainstorming... Might it not be possible to create a "library" of keyboard symbols (or combinations of symbols) that represent certain things? I'm expanding from the {R} in an earlier post. For example ^This is Bold^, !This is Italic! and ~This is Underline~ where combining the enclosing symbols (i.e. ^~) would likewise combine the effect. Perhaps I'm taking out of turn because I haven't yet looked at the library. Also, it would be nice to be able to load and display a pre-formatted RTF file.
More brainstorming... Might it not be possible to create a "library" of keyboard symbols (or combinations of symbols) that represent certain things? I'm expanding from the {R} in an earlier post. For example ^This is Bold^, !This is Italic! and ~This is Underline~ where combining the enclosing symbols (i.e. ^~) would likewise combine the effect. Perhaps I'm taking out of turn because I haven't yet looked at the library. Also, it would be nice to be able to load and display a pre-formatted RTF file.