[Gambas-user] TextEdit as RichText Editor

Bruce Steers bsteers4 at gmail.com
Tue Jun 21 10:56:01 CEST 2022


On Fri, 17 Jun 2022 at 15:52, <james at lixce.com> wrote:

> Some text attributes can be read and changed directly from the TextEdit
> control using
> for Example:
>
> If TextEdit1.Format.Font.Bold  Then TextEdit1.Format.Font.Bold = False
>
> This applies to the selected text or the entire paragraph if no text is
> selected.
>
> For more complex formatting you will have to analyze the RichText. You can
> pull the RichText for the paragraph by converting the TextEdit.Pos to a
> paragraph number then setting the position to the begining of the paragraph
> and selecting the text to the beginning of the next paragraph.
>
> inPara = TextEdit1.ToParagraph(TextEdit1.Pos)
> Textedit1.Select(TextEdit1.ToPos(inPara, 0), (TextEdit1.ToPos(inPara + 1,
> 0) - 1)
> stRicTxt = TextEdit1.Selection.RichText
>
> You will always get that funky header that you have to strip off and the
> dig through the html -ish RTF.
>
> Advanced formating is NOT trivial my TextEdit based Word Processor is
> about 7000 lines and still growing for edge cases.  I gave up analyzing
> paragraphs and other elements directly and build an array of every Element
> (paragraphs, list items, table cells etc.) and literally update it on every
> keystroke; which, thanks to the amazing speed of Gambas,
> actually works.
>
> Final Note: The TextEdit control stores formatting in a valid, but very
> ugly, html syntax but it is really good at accepting much more human
> readable html and displaying it.  This allows you to use things like:
> TextEdit1.Selection.RichText  = "<h1>This is a Header</h1>"
>
> Which will be converted internally to:
> <h1 style=" margin-top:12px; margin-bottom:12px; margin-left:0px;
> margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style="
> font-size:xx-large; font-weight:600;">This is a header</span></h1>
>
> Regards, -j
>

Thank you James , that's some cool info :)

BruceS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20220621/55b3543a/attachment.htm>


More information about the User mailing list