Thank you. That was extremely helpful, but my example code didn't go far enough. Apparently paragraphs are slightly different and I have another quick question related to styles.
So I have modified your sample answer to add in a paragraph with the following requirement: there are 6 extra units above and below the "bbb" paragraph, but if two "bbb" paragraphs are immediately adjacent to each other, there is not extra space between the two. That is the idea formatting, but if there is no way to implement it (because negative units do not work), I can find some other style set-up to accomplish the requirement. For the demo code, just change the -6 to an extra 10 units between the two paragraphs if the negative units are a problem for this demo.
This will show me both how to deal with paragraph styles and how to handle one paragraph style that follows another.
So, Question #1, do styles handle negative spacing (as in the code below)?
Question #2, I want to make sure that I am properly handling one paragraph style that follows another
Question #3, how do I fix the error ("generates an error: [bcc32c Error] Unit1.cpp(314): cannot initialize a parameter of type 'Rvstyle::TCustomRVParaInfo *' with an lvalue of type 'Rvstyle::TRVStyleTemplate *' RVStyle.hpp(1393): passing argument to parameter 'AParaStyle'") when I am trying to update the paragraph style?
Code: Select all
TRVStyle * Style = rve->Style;
TRVStyleTemplate * Template;
TCustomRVParaInfo * ParaStyle;
TCustomRVFontInfo * TextStyle;
TRVTabInfo* Tab;
UnicodeString font = "Arial";
int fontSize = 12;
// =================== Creating style templates
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);
Template->ValidTextProperties << rvfiFontName << rvfiSize << rvfiColor;
Template->ValidParaProperties << rvpiAlignment << rvpiSpaceBefore
<< rvpiSpaceAfter << rvpiTabs;
Template = Style->StyleTemplates->Add();
Template->Kind = rvstkText;
Template->NextId = -1;
Template->Name = "AAA";
TextStyle = Template->TextStyle;
TextStyle->Style << fsBold;
TextStyle->Color = clBlue;
Template->ValidTextProperties << rvfiBold << rvfiColor;
// Newly inserted test case for paragraph settings
Template = Style->StyleTemplates->Add();
Template->Kind = rvstkPara;
Template->Name = "bbb";
//Template->NextId = ... this is done after the follow-on paragraph style is added
ParaStyle = Template->ParaStyle;
ParaStyle->SpaceBefore = 6;
ParaStyle->SpaceAfter = 6;
Template->ValidParaProperties << rvpiSpaceBefore << rvpiSpaceAfter;
int titleParaSubscript = Style->StyleTemplates->Count - 1;
int titleParaId = Template->Id;
Template = Style->StyleTemplates->Add();
Template->Kind = rvstkPara;
Template->Name = "bbbRepeat";
Template->ParentId = titleParaId;
Template->NextId = Template->Id;
ParaStyle = Template->ParaStyle;
ParaStyle->SpaceBefore = -6; // Question #1: does negative spacing work here?
ParaStyle->SpaceAfter = 6;
Template->ValidParaProperties << rvpiSpaceBefore << rvpiSpaceAfter;
Template = Style->StyleTemplates->Items[titleParaSubscript]; //Question #2: Is this a proper way to handle one paragraph style that follows another
Template->NextId = titleParaId;
// End newly inserted code
// =================== Creating text and paragraph styles
Style->TextStyles->Clear();
Style->ParaStyles->Clear();
Style->ListStyles->Clear();
TRVStyleTemplate * NormalStyleTemplate = rvs->StyleTemplates->NormalStyleTemplate;
TRVStyleTemplate * TextStyleTemplate;
// creating a paragraph style linked to "Normal"
ParaStyle = Style->ParaStyles->Add();
// linking "Normal" to ParaStyle
ParaStyle->StyleTemplateId = NormalStyleTemplate->Id;
// changing properties of ParaStyle according to its StyleTemplate
NormalStyleTemplate->ApplyToParaStyle(ParaStyle);
// Newly inserted test case for paragraph settings
ParaStyle = Style->ParaStyles->Add();
ParaStyle->StyleTemplateId = NormalStyleTemplate->Id;
TRVStyleTemplate * ParaStyleTemplate = rvs->StyleTemplates->FindItemByName("bbb");
ParaStyleTemplate->ApplyToParaStyle(ParaStyleTemplate); // Question #3: this generates an error
ParaStyle = Style->ParaStyles->Add();
ParaStyle->StyleTemplateId = NormalStyleTemplate->Id;
ParaStyleTemplate = rvs->StyleTemplates->FindItemByName("bbbRepeat");
//ParaStyleTemplate->ApplyToParaStyle(ParaStyleTemplate); // generates same error as Question 3
// End newly inserted code
// creating a text style that is not linked to StyleTemplate, but
// should be used in "Normal" paragraphs
TextStyle = Style->TextStyles->Add();
TextStyle->ParaStyleTemplateId = NormalStyleTemplate->Id;
// changing properties of ParaStyle accordingly
TextStyleTemplate = NULL;
TextStyleTemplate->ApplyToTextStyle(TextStyle, NormalStyleTemplate);
// creating a text style that is linked to "AAA", and
// should be used in "Normal" paragraphs
TextStyle = Style->TextStyles->Add();
TextStyle->ParaStyleTemplateId = NormalStyleTemplate->Id;
// changing properties of ParaStyle accordingly
TextStyleTemplate = rvs->StyleTemplates->FindItemByName("AAA");
TextStyleTemplate->ApplyToTextStyle(TextStyle, NormalStyleTemplate);
/*
Now, we created
ParaStyles->Items[0] linked to "Normal"
TextStyles->Items[0] for placing in "Normal" paragraphs, not linked to ST
TextStyles->Items[1] for placing in "Normal" paragraphs, linked to "AAA"
*/
// sample document
rve->Clear();
rve->AddNL("Hi there", 0, 0); // "Normal"
rve->AddNL("Hi there", 1, 0); // "Normal" + "AAA"
rve->Format();