Page 1 of 1
remove 1 or more font styles from the set of styles
Posted: Mon Jan 08, 2007 9:01 pm
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
Posted: Tue Jan 09, 2007 12:33 pm
by Sergey Tkachenko
Do you want to change style of the item?
Assign new value to RVData.GetItem(i).StyleNo
not really
Posted: Tue Jan 09, 2007 8:34 pm
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.
Posted: Thu Jan 11, 2007 2:24 pm
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]);
Posted: Mon Jul 20, 2015 2:18 pm
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.
Posted: Mon Jul 20, 2015 6:11 pm
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.