Protected section not set automatically on RTF file loading

General TRichView support forum. Please post your questions here
Marcer
Posts: 31
Joined: Mon Mar 23, 2009 1:54 pm

Protected section not set automatically on RTF file loading

Post by Marcer »

I load a RTF file and the protected section text is not protected in RichViewEdit. Is it possible to automatically set the protected section on loading RTF file?

My RTF file include this :

{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang3084{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
\pard\sl276\slmult1\f0\fs22\lang12
Test
\par \protect Protect zone
\par Protect Zone
\par Protect Zone
\par \plain Test}

Best regards
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Sorry, the current version of TRichView does not save and does not load protection from RTF.
As for the specific \protect keyword, I do not know even how it should work. I loaded your RTF in MS Word and in RichEdit, and I can see no effect.

You can implement saving and loading \protect in RTF yourself. However, it is possible to implement only for TextStyles, not ParaStyles or non-text items.

Here is a sample code: http://www.trichview.com/support/files/ ... operty.zip
This example shows how to implement an additional text property (Shadow) and how to save and load it as \shad to RTF.
You can use a similar approach for \protect. It is even simpler, since you do not need new properties and can use the existing Protection property.
This example subclass TRVStyle component to use a subclassed TextStyles (TMyFontInfo instead of TFontInfo). Instead of subclassing TRVStyle, you can assign your class (inherited from TFontInfo) to the global DefRVFontInfoClass variable.
Like in this example, you also need to subclass TRVRTFCharProperties to store property load from RTF, and TRVRTFStyleComparer.
Marcer
Posts: 31
Joined: Mon Mar 23, 2009 1:54 pm

Post by Marcer »

Thanks Sergey!! I used this way to implement my protection structure and it's functionnal.
filo
Posts: 22
Joined: Wed Apr 12, 2017 12:28 pm

Re:

Post by filo »

Sergey Tkachenko wrote: Fri Oct 25, 2013 9:25 pm Sorry, the current version of TRichView does not save and does not load protection from RTF.
As for the specific \protect keyword, I do not know even how it should work. I loaded your RTF in MS Word and in RichEdit, and I can see no effect.
Hi,
is there any progress about straightforward reading (and writing) of RTF "protect" keyword from/to file or I still have to use a workaround with sample example above?

According to RTF 1.9.1 specs (Appendix C: Control Words Introduced by Specific/Other Microsoft Products):
\protect Character formatting flag used by RichEdit to mark text runs as protected. Introduced for Outlook 97.
\protect turns on protection and \protect0 turns it off.
Thank you for answer.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Protected section not set automatically on RTF file loading

Post by Sergey Tkachenko »

Do you know any application supporting this keyword?

I tried the code in the first message in this topic, both in the original form and with changing \protect to \protect1.
It seems this keyword is ignored both by Word and WordPad.
filo
Posts: 22
Joined: Wed Apr 12, 2017 12:28 pm

Re: Protected section not set automatically on RTF file loading

Post by filo »

Thank you for your quick response.
It seems this keyword is ignored both by Word and WordPad.
Yes, you are right.
Do you know any application supporting this keyword?
I think it should be any application which uses a RichEdit control from Microsoft, like Appendix C RTF 1.9.1 specs says.
Directly or as descendant, it doesn't matter.

We use a standard Delphi TRichEdit control from ComCtrls unit with property SelAttributes: TTextAttributes.
TTextAttributes has property ConsistentAttributes: TConsistentAttributes and there is a value caProtected within set TConsistentAttribute.

Code: Select all

 TConsistentAttribute = (caBold, caColor, caFace, caItalic,
    caSize, caStrikeOut, caUnderline, caProtected);
  TConsistentAttributes = set of TConsistentAttribute;
The caProtected is transformed to "protect" tag in generated RTF

Sample RTF (output from Delphi TRTFEdit) with one protected paragraph and one protected starting part of sentence:
{\rtf1\ansi\ansicpg1250\deff0\deflang1029\deflangfe1029{\fonttbl{\f0\fswiss\fprq2\fcharset238{\*\fname Arial;}Arial CE;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\nowidctlpar\fi720\li1440\cf1\f0\fs20 This is a normal text\par
\protect This is a protected text\protect0\par
This is a normal text\par
\protect This is a protected part\protect0 and this is unprotected part\par
foo\par
}
Support of this "protect" tag is critical for our products. Due to many circumstances we must load and save RTF with this tag.

Thank you for your answer.
filo
Posts: 22
Joined: Wed Apr 12, 2017 12:28 pm

Re: Protected section not set automatically on RTF file loading

Post by filo »

Any news?
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Protected section not set automatically on RTF file loading

Post by Sergey Tkachenko »

I can add this tag, it's not a problem.

But which protection option it corresponds to?
ModifyProtect, yes, obviously.
DeleteProtect?
StyleProtect?
filo
Posts: 22
Joined: Wed Apr 12, 2017 12:28 pm

Re: Protected section not set automatically on RTF file loading

Post by filo »

Thanks, I would like to keep a standard behavior of Delphi's TRichEdit if it is possible.
So full protection - no text modification, no delete, no style change. You can do nothing with protected text in TRichEdit. You can't even delete selected text if it contains a protected text inside.
filo
Posts: 22
Joined: Wed Apr 12, 2017 12:28 pm

Re: Protected section not set automatically on RTF file loading

Post by filo »

Sergey,
could you tell me when do you plan to release a new build with support of mentioned protect tag?
I must do a complete tests of TRichView before I will get a permission to buy your components.
Thank you.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Protected section not set automatically on RTF file loading

Post by Sergey Tkachenko »

I plan to upload a new update in the next couple of days, we need to complete new equation editor.
filo
Posts: 22
Joined: Wed Apr 12, 2017 12:28 pm

Re: Protected section not set automatically on RTF file loading

Post by filo »

Perfect, thank you.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Protected section not set automatically on RTF file loading

Post by Sergey Tkachenko »

A new version with \protect support is uploaded (it will be announced tomorrow)
filo
Posts: 22
Joined: Wed Apr 12, 2017 12:28 pm

Re: Protected section not set automatically on RTF file loading

Post by filo »

Sergey,
thank you, I have found 2 minor issues:
1. A caret is moving forward when delete key is pressed. Please disable VK_DELETE on protected text as Delphi's TRIchEdit does. The backspace key is OK.
2. If caret's position is inside of protected text and ctrl+v (or Paste from menu) is pressed, the caret jumps to beginning of the document.


filo wrote: Tue Apr 18, 2017 8:27 pmSo full protection - no text modification, no delete, no style change.
I'm sorry about misleading information about the style, I meant font style only. :? I need to have a chance for setting/changing background color of protected text.

I don't know about details, how do you process the RTF protect tag, is it a combination of Protection.rvprModifyProtect and rvprDeleteProtect?
Or you have made complete some new hidden protected style? I'm thinking about method how to detect protected text programmatically for background color change ...

Thank you for your patience and looking forward to your reply.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Protected section not set automatically on RTF file loading

Post by Sergey Tkachenko »

I fixed the issues with caret moving when pressing Delete or inserting RVF in the protected text. The fix will be included in the next update.

As for the protection. The component reads RTF protection flags as the following protection options: [rvprModifyProtect, rvprDeleteProtect, rvprSticking, rvprStyleProtect, rvprDoNotAutoSwitch]
rvprModifyProtect disallows changing text.
rvprDeleteProtect disallows deleting as a whole.
rvprSticking disallows insertion between protected text items.
rvprStyleProtect disallows changing text style.
rvprDoNotAutoSwitch disallows this style to be current (and thus, typing new text of this protected style).
More details: http://www.trichview.com/help/idh_tcust ... ction.html

The most questionable is rvprStyleProtect protection. It disallows applying any changes to text properties of the protected text.
Unfortunately, our editor does not have a standard mechanism to allow changing only some text properties (for example, disallowing changing font name, but allowing changing text color).
Whether it a real problem, depends on how you want to change text fore- or background color.
Note that protection options protect only from editing operations, so, if you use non-editing methods for changing text style, you can change protected text.
Also, actually, rvprStyleProtect does not protect from changing text style using ApplyStyleConversion method: the program which provides OnStyleConversion event must check for this protection option itself. For example, any change of text properties performed by RichViewActions respects this option. But if you implement this operation yourself, you are free to implement it specially.
If you describe how you want to change text properties of the protected text, I will try to help.
Post Reply