'wrong' caret if copying text from internet

General TRichView support forum. Please post your questions here
Post Reply
j&b
Posts: 184
Joined: Mon Sep 05, 2005 1:35 pm

'wrong' caret if copying text from internet

Post by j&b »

Image
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You included rvoShowSpecialCharacters in RichViewEdit.Options.
So you can see dots in place of spaces, a pilcrow character at the end of paragraph, and a paragraph level.
This text, obviously, was copied from the heading level 2 (<h2>...</h2>) of the web page, so you can see "(2)" next to a pilcrow character, because this text is pasted as a heading level 2.

How to convert it to normal text:
If you use RichViewActions, select this text, open the paragraph dialog, and choose "outline level"="body text" ( http://www.trichview.com/shots/rva/para ... elevel.png )
If you do not use RichViewAction, implement a command (paragraph style conversion) that will change OutlineLevel property of paragraph style (use ApplyParaStyleConversion + OnParaStyleConversion event)

How to hide this character:
Remove rvscParagraphAttrs from RVVisibleSpecialCharacters (global variable defined in RVStyle unit). It will hide "(2)" even in show-special-character mode. However, this text will still be a heading of level 2, and will be exported to HTML and RTF as a heading.
j&b
Posts: 184
Joined: Mon Sep 05, 2005 1:35 pm

Post by j&b »

Image

Why are wrong ?

My code:

procedure TForm1.sbTesten1Click(Sender: TObject);
begin
memo.ApplyParaStyle(PARA_OUTLINELEVEL_0);
memo.format;
end;



var
Form1: TForm1;

implementation
{$R *.DFM}


const
//rv
rv_MAKEBOLD = 1;
..

// Parameters for ApplyParaStyleConversion
PARA_ALIGNMENT = 1;
..
PARA_OUTLINELEVEL_0 = 9;
//rv-Ende


procedure TForm1.memoParaStyleConversion(Sender: TCustomRichViewEdit; StyleNo, UserData: Integer; AppliedToText: Boolean; var NewStyleNo: Integer);
var ParaInfo: TParaInfo;
Tabs: TRVTabInfos;
za, aa, bb: integer;
begin
ParaInfo := TParaInfo.Create(nil);
try
ParaInfo.Assign(rvs.ParaStyles[StyleNo]);
case UserData of
PARA_ALIGNMENT:
ParaInfo.Alignment := GetAlignmentFromUI;
.........

PARA_COLOR: ParaInfo.Background.Color := cd.Color;
PARA_OUTLINELEVEL_0: ParaInfo.outlineLevel:= 0;
end;
NewStyleNo := rvs.ParaStyles.FindSuchStyle(StyleNo,ParaInfo,RVAllParaInfoProperties);
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Do you have a code for creating a new paragraph style in memoParaStyleConversion, if FindSuchStyle returns -1?
j&b
Posts: 184
Joined: Mon Sep 05, 2005 1:35 pm

Post by j&b »

Do you mean this ?

PARA_COLOR: ParaInfo.Background.Color := cd.Color;
PARA_OUTLINELEVEL_0: ParaInfo.outlineLevel:= 0;
end;

NewStyleNo := rvs.ParaStyles.FindSuchStyle(StyleNo,ParaInfo,RVAllParaInfoProperties);

if NewStyleNo=-1 then begin
rvs.ParaStyles.Add;
NewStyleNo := rvs.ParaStyles.Count-1;
rvs.ParaStyles[NewStyleNo].Assign(ParaInfo);
rvs.ParaStyles[NewStyleNo].Standard := False;
end;
finally
ParaInfo.Free;
end;
j&b
Posts: 184
Joined: Mon Sep 05, 2005 1:35 pm

Post by j&b »

j&b wrote:Do you mean this ?

PARA_COLOR: ParaInfo.Background.Color := cd.Color;
PARA_OUTLINELEVEL_0: ParaInfo.outlineLevel:= 0;
end;

NewStyleNo := rvs.ParaStyles.FindSuchStyle(StyleNo,ParaInfo,RVAllParaInfoProperties);

if NewStyleNo=-1 then begin
rvs.ParaStyles.Add;
NewStyleNo := rvs.ParaStyles.Count-1;
rvs.ParaStyles[NewStyleNo].Assign(ParaInfo);
rvs.ParaStyles[NewStyleNo].Standard := False;
end;
finally
ParaInfo.Free;
end;

YES
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

The code is correct.
However, red border around paragraphs means that incorrect index of paragraph style is used (<0 or >=rvs.ParaStyles.Count).
Probably, error is in some other place.
Can you create a simple project to reproduce this problem and send it to me by email?
j&b
Posts: 184
Joined: Mon Sep 05, 2005 1:35 pm

Post by j&b »

Image

2. Solution:

procedure TForm1.memoParaStyleConversion(...)
... //in my 1. solution I called memoParaStyle(...)
PARA_OUTLINELEVEL_0: ParaInfo.outlineLevel:= 0; // Whether 0, -1 or -x I get a paragraph level
end;
NewStyleNo := rvs.ParaStyles.FindSuchStyle(StyleNo,ParaInfo,RVAllParaInfoProperties);
if NewStyleNo<0 then begin //=-1
...

procedure TForm1.sbTesten1Click(Sender: TObject);
begin
memo.ApplyParaStyleConversion (PARA_OUTLINELEVEL_0);
end;


Sergey, do you have a folder on your homepage where someone (with login) can upload the images for a topic ?
All my images for this topic are lost if I delete them after a time. I think an image often is better than a text.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

As I understand, you already found the bug: you called ApplyParaStyle instead of ApplyParaStyleConversion.
By the way, after applying this procedure, you can see a square next to pilcrow character for these paragraphs. This square is displayed because these paragraphs have rvpaoKeepWithNext in Options. Probably, it makes sense to remove this option in the same command.

Unfortunately, I cannot open ftp for uploading files, because I cannot control the content that will be uploaded there, if somebody decide to upload infected files.
j&b
Posts: 184
Joined: Mon Sep 05, 2005 1:35 pm

Post by j&b »

...

Sergey:
... you can see a square next to pilcrow character for these paragraphs.
This square is displayed because these paragraphs have rvpaoKeepWithNext in Options.
Probably, it makes sense to remove this option in the same command:

...
PARA_OUTLINELEVEL_0:
begin
ParaInfo.outlineLevel:= 0;
ParaInfo.Options := ParaInfo.Options-[rvpaoKeepWithNext];
end;
...

Thank you. All runs fine.[/b]
Post Reply