From b59245f0578c57300951d57015fd93f7b3e616d6 Mon Sep 17 00:00:00 2001 From: Michael van Canneyt Date: Mon, 26 Nov 2012 11:28:29 +0000 Subject: RichTextView syntax tag improvements 1) h1, h2 h3 are now ended by /h1 /h2 /h3 2) and are changed to 3) The size part of the font tag is now optional. I suspect a small change is still needed in order to apply the font size if one is specified anyway. I put a comment in the text for that. 4) I adapted the sample01.txt so it reflects the 1. and 2. changes. --- .../components/richtext/RichTextDocumentUnit.pas | 12 ++++--- docview/components/richtext/RichTextStyleUnit.pas | 18 +++++++--- docview/components/richtext/testapp/sample01.txt | 38 +++++++++++----------- 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/docview/components/richtext/RichTextDocumentUnit.pas b/docview/components/richtext/RichTextDocumentUnit.pas index f5d83dde..89f0bf46 100644 --- a/docview/components/richtext/RichTextDocumentUnit.pas +++ b/docview/components/richtext/RichTextDocumentUnit.pas @@ -18,11 +18,12 @@ type ttItalic, ttItalicOff, ttUnderline, ttUnderlineOff, ttFixedWidthOn, ttFixedWidthOff, - ttHeading1, ttHeading2, ttHeading3, ttHeadingOff, + ttHeading1, ttHeading2, ttHeading3, + ttHeading1Off, ttHeading2Off, ttHeading3Off, ttColor, ttColorOff, ttBackgroundColor, ttBackgroundColorOff, ttRed, ttBlue, ttGreen, ttBlack, - ttWrap, + ttnoWrap,ttnoWrapOff, ttAlign, ttBeginLink, ttEndLink, ttSetLeftMargin, ttSetRightMargin, @@ -72,7 +73,9 @@ const 'h1', 'h2', 'h3', - '/h', + '/h1', + '/h2', + '/h3', 'color', '/color', 'backcolor', @@ -81,7 +84,8 @@ const 'blue', 'green', 'black', - 'wrap', + 'nowrap', + '/nowrap', 'align', 'link', '/link', diff --git a/docview/components/richtext/RichTextStyleUnit.pas b/docview/components/richtext/RichTextStyleUnit.pas index 7effc5ee..98f5adfa 100644 --- a/docview/components/richtext/RichTextStyleUnit.pas +++ b/docview/components/richtext/RichTextStyleUnit.pas @@ -198,7 +198,9 @@ ProfileEvent('DEBUG: ApplyStyleTag >>>'); Style.FontAttributes := GetFPGuiFontAttributes(ASettings.Heading3Font); end; - ttHeadingOff: + ttHeading1Off, + ttHeading2Off, + ttHeading3Off: begin Style.FontNameSize := Copy(ASettings.NormalFont.FontDesc, 1, Pos(':', ASettings.NormalFont.FontDesc)-1); Style.FontAttributes := GetFPGuiFontAttributes(ASettings.NormalFont); @@ -209,7 +211,8 @@ ProfileEvent('DEBUG: ApplyStyleTag >>>'); tmpFontParts := TStringList.Create; StrExtractStringsQuoted(tmpFontParts, Tag.Arguments); FontFaceName := tmpFontParts[0]; - FontSizeString := tmpFontParts[1]; + if tmpFontParts.Count=2 then + FontSizeString := tmpFontParts[1]; tmpFontParts.Free; NewStyle := Style; @@ -222,9 +225,11 @@ ProfileEvent('DEBUG: ApplyStyleTag >>>'); XSizeStr := tmpFontParts[0]; YSizeStr := tmpFontParts[1]; tmpFontParts.Destroy; + // This probably needs to be enhanced to extract the font name and size first. NewStyle.FontNameSize := NewStyle.FontNameSize + '-' + YSizeStr; end - else + else if (FontSizeString<>'') then + // Same here NewStyle.FontNameSize := NewStyle.FontNameSize + '-' + FontSizeString; if ( NewStyle.FontNameSize <> '' ) then @@ -266,8 +271,11 @@ ProfileEvent('DEBUG: ApplyStyleTag >>>'); ttAlign: Style.Alignment := GetTagTextAlignment( Tag.Arguments, ASettings.FDefaultAlignment ); - ttWrap: - Style.Wrap := GetTagTextWrap( Tag.Arguments ); + ttnoWrap: + Style.Wrap := False; + + ttnoWrapOff: + Style.Wrap := True; ttSetLeftMargin, ttSetRightMargin: diff --git a/docview/components/richtext/testapp/sample01.txt b/docview/components/richtext/testapp/sample01.txt index 9713e63b..a8653ac8 100644 --- a/docview/components/richtext/testapp/sample01.txt +++ b/docview/components/richtext/testapp/sample01.txt @@ -1,14 +1,14 @@ -

RichTextView formatting syntax +

RichTextView formatting syntax

It has a HTML-like set of tags. Not very strict, so tag pairs don't have to match up. For example <<<< tags are often used to get you back to default (normal) text formatting. To display a physical tags in your text, you need to prefix the << symbol of a tag, with an extra << symbol. -

Margins +

Margins

The following text has a left margin of 10 spaces and a right margin of 5 spaces. - + 1 2 3 4 5 6 12345678901234567890123456789012345678901234567890123456789012345 - + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam tincidunt lacinia diam, a egestas arcu bibendum sit amet. Proin erat mauris, vehicula id auctor aliquam, semper id turpis. Etiam iaculis lectus sit amet velit molestie euismod. Proin vel fermentum sem. Vivamus ut odio ligula, et egestas purus. Pellentesque eu turpis vitae ante adipiscing lacinia. Nulla dignissim, ligula id eleifend accumsan, sapien lacus condimentum nulla, eu pulvinar risus magna quis turpis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In vel semper nunc. Nulla eget justo at dolor vestibulum aliquam. Aenean commodo egestas odio, a rutrum sapien fringilla et. @@ -20,29 +20,29 @@ The following text has a left margin of 10 spaces and a right margin of 5 spaces Now the margin is set back to 0 (default). -

Headings +

Headings

Then we have some general text texts like heading 1-3, normal text and fixed width text. -

This is Heading 1 font -

This is Heading 2 font -

This is Heading 3 font +

This is Heading 1 font

+

This is Heading 2 font

+

This is Heading 3 font

This is normal text This is fixed font text -

Text Color +

Text Color

We can also specify text colors like green, blue, or some RRGGBB specified color. We can also specific a text background color. -

Alternative Fonts +

Alternative Fonts

-This sentence is in Courier New 8 font. +This sentence is in Courier New 8 font. -This sentence is in 'Times New Roman' 12 font. +This sentence is in 'Times New Roman' 12 font. -This sentence is in Helvetica 18 font. +This sentence is in Helvetica 18 font. This sentence is in the default system font. -

Text alignment +

Text alignment

This text is left aligned. This text is centre aligned. @@ -54,9 +54,9 @@ Images follow the same alignment as text. This is back to normal. -

ASCII or Unicode text art -Using the << is handy to create text art. If your FixedFont supports Unicode drawing characters, then you can make your text art look even better. - +

ASCII or Unicode text art

+Using the << is handy to create text art. If your FixedFont supports Unicode drawing characters, then you can make your text art look even better. + +-------------------------------------+ |File Edit | View | Options Help | +-------------------------------------+ @@ -65,9 +65,9 @@ Using the << is handy to create text art. If your FixedFont support +--------------------+ | By . . . | +--------------------+ - + -

HyperLinks +

HyperLinks

RichTextView also supports hyperlinks. Simply use the < syntax, where "xyz" is the link text that will be sent to the OnClickLink() and OnOverLink() events. By default the link text will appear in the same color and styling as the surrounding text. If you want to make it more visible, use the < tags. -- cgit v1.2.3-70-g09d2