Styles: rvstkParaText vs rvstkPara vs rvstkText
Posted: Sat Aug 17, 2019 12:02 am
I am struggling to understand where to use these constants. It is obvious Para vs Text, but it seems like "Normal" template style would be both (i.e., that should be ParaText). However, I have gotten "wrong kind of StyleTemplate parent" run time errors if I try to derive a text style from a Normal template (e.g., uncomment the line in the code below).
Also, can you tell me what is wrong with filling the style template this way. I want to do something like this to allow dynamically setting it based on user's settings, so the easiest thing to do in my situation is build it all in code. The problem here is that counts never get any larger than zero and the resulting display of the line printed (on my test machine turns out red, rather than either black or blue, the only colors I specified).
If it is not too difficult, can you fix this small sample?
Also, can you tell me what is wrong with filling the style template this way. I want to do something like this to allow dynamically setting it based on user's settings, so the easiest thing to do in my situation is build it all in code. The problem here is that counts never get any larger than zero and the resulting display of the line printed (on my test machine turns out red, rather than either black or blue, the only colors I specified).
If it is not too difficult, can you fix this small sample?
Code: Select all
int __fastcall getTextStyleIdByName(TRichView * rv, UnicodeString styleName, int defaultVal=-1) {
int rtnVal = defaultVal;
TRVStyle * Style = rv->Style;
for (int i = 0; i < Style->TextStyles->Count ; i++) { // Count turns out to be zero
if (Style->TextStyles->Items[i]->StyleName == styleName) {
rtnVal = i;
break;
}
}
return rtnVal;
}
int __fastcall getParaStyleIdByName(TRichView * rv, UnicodeString styleName, int defaultVal=-1) {
int rtnVal = defaultVal;
TRVStyle * Style = rv->Style;
for (int i = 0; i < Style->ParaStyles->Count ; i++) { // Counts turns out to be zero
if (Style->ParaStyles->Items[i]->StyleName == styleName) {
rtnVal = i;
break;
}
}
return rtnVal;
}
void __fastcall TForm1::btnDisplayClick(TObject *Sender)
{
TRVStyle * Style = rv->Style;
TRVStyleTemplate * Template;
TRVSTParaInfo * ParaStyle;
TRVSTFontInfo * TextStyle;
TRVTabInfo* Tab;
int styleNormal;
UnicodeString font = "Arial";
int fontSize = 12;
Style->TextStyles->Clear();
Style->ParaStyles->Clear();
Style->ListStyles->Clear();
Template = Style->StyleTemplates->Add();
Template->Kind = rvstkParaText;
Template->Name = "Normal";
TextStyle = Template->TextStyle;
TextStyle->FontName = font;
TextStyle->SizeDouble = fontSize * 2;
TextStyle->Color = clBlack;
ParaStyle = Template->ParaStyle;
ParaStyle->Alignment = rvaLeft;
ParaStyle->SpaceBefore = 0;
ParaStyle->SpaceAfter = 0;
Tab = ParaStyle->Tabs->Add();
Tab->Position = Style->RVUnitsToUnits(0.4, rvuInches);
Tab = ParaStyle->Tabs->Add();
Tab->Position = Style->RVUnitsToUnits(0.8, rvuInches);
Tab = ParaStyle->Tabs->Add();
Tab->Position = Style->RVUnitsToUnits(1.2, rvuInches);
Tab = ParaStyle->Tabs->Add();
Tab->Position = Style->RVUnitsToUnits(1.6, rvuInches);
Tab = ParaStyle->Tabs->Add();
Tab->Position = Style->RVUnitsToUnits(2.0, rvuInches);
styleNormal = Template->Id;
Template = Style->StyleTemplates->Add();
//Template->Kind = rvstkText; // Causes "Wrong kind of StyleTemplate parent" error
Template->ParentId = styleNormal;
Template->NextId = styleNormal;
Template->Name = "AAA";
TextStyle = Template->TextStyle;
TextStyle->Style << fsBold;
TextStyle->Color = clBlue;
rv->AddNL("Hi there", getTextStyleIdByName(rv, "AAA"), getParaStyleIdByName(rv, "Normal"));
rv->FormatTail();
}