remove 1 or more font styles from the set of styles

General TRichView support forum. Please post your questions here
Post Reply
alogrep
Posts: 52
Joined: Fri Oct 27, 2006 5:25 pm

remove 1 or more font styles from the set of styles

Post by alogrep »

Hi

I want to do this: when the user creates a template (with fields in it),
they can select from a list of field, and I put the field italic+bold+underlined+overlined in the text.
When the user uses the template, the fields are filled in. This is the code
RVData.SetItemTexta(i, GetFieldValueFromDatabase(FieldName));
how can I remove the overline and underline from the value that will replace Fieldname?
Thanks
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Do you want to change style of the item?
Assign new value to RVData.GetItem(i).StyleNo
alogrep
Posts: 52
Joined: Fri Oct 27, 2006 5:25 pm

not really

Post by alogrep »

No
I cannot assign a style number, I do not know what style it will be.
The user may choose any style (i.e. bold, italic, underlined, overlined, and any size he likes).
I only want to do "whatever the user chooses, MINUS overline" for example. I want to take only overline off the styles, I do not know what's left.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Do I understand you right: you want, basing on the item text, change its font, for example making it not underlined?

The function below returns index of text style having all properties of RVStyle.TextStyles[BaseStyleNo], but with MinusStyles excluded from Style property

Code: Select all

function GetStyleMinus(RVStyle: TRVStyle; BaseStyleNo: Integer;
  MinusStyles: TFontStyles): Integer;
var ts: TFontInfo;
begin
  ts := TFontInfo.Create(nil);
  ts.Assign(RVStyle.TextStyles[BaseStyleNo]);
  ts.Style := ts.Style-MinusStyles;
  Result := RVStyle.TextStyles.FindSuchStyle(BaseStyleNo, ts,
    RVAllFontInfoProperties);
  if Result<0 then begin
    RVStyle.TextStyles.Add;
    Result := RVStyle.TextStyles.Count-1;
    RVStyle.TextStyles[Result].Assign(ts);
    RVStyle.TextStyles[Result].Standard := False;
  end;
end;
Using:

Code: Select all

FieldValue := GetFieldValueFromDatabase(FieldName);
RVData.SetItemTexta(i, FieldValue); 
if ShouldRemoveUnderline(FieldValue) then
  RVData.GetItem(i).StyleNo := GetStyleMinus(RVData.GetRVStyle,
    RVData.GetItemStyle(i), [fsUnderline]);
Bjoern
Posts: 21
Joined: Tue May 11, 2010 4:05 pm

Post by Bjoern »

Hello,

this code works fine for removing styles of the font like bold, etc ... is there an easy way like this to remove ParaStyles like rvaCenter?

I've tried to modify your example to do that, but i'm not very familiar with the handling of paragraphs, all my attempts does't work.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

While the code in my previous reply still works, newer versions of TRichView allow to implement it simpler:

Code: Select all

function GetStyleMinus(RVStyle: TRVStyle; BaseStyleNo: Integer;
  MinusStyles: TFontStyles): Integer;
var ts: TFontInfo;
begin
  ts := TFontInfo.Create(nil);
  ts.Assign(RVStyle.TextStyles[BaseStyleNo]);
  ts.Style := ts.Style-MinusStyles;
  Result := RVStyle.FindTextStyle(ts);
end;
For paragraphs, it's the same. Instead of TFontInfo use TParaInfo, instead of FindTextStyle use FindParaStyle.

Code: Select all

function GetParaWithAlignment(RVStyle: TRVStyle; BaseParaNo: Integer;
  Alignment: TRVAlignment): Integer;
var ps: TParaInfo;
begin
  ps := TParaInfo.Create(nil);
  ps.Assign(RVStyle.ParaStyles[BaseParaNo]);
  ps.Alignment := Alignment;
  Result := RVStyle.FindParaStyle(ps);
end;
To "remove" all alignments, pass rvaLeft to the last parameter.
To change paragraph style as non-editing (i.e. not undoable) operation, assign the returned value to GetItem(I).ParaNo.
Important: all items in the same paragraph must have equal value of ParaNo! Paragraphs starts from items for which IsParaStart(I) return True.
Post Reply