Change relative text size of all characters in current selection
Rochelle, we can increase the font size of the selected text in two ways:
- Using the IncreaseFontSizeCommand.
- Iterating through the inlines (SpanAdv) within the selection and increasing the font size.
Using the Increase Font Size Command:
This command is used to increase the font size of the text within the
selection. We need to pass the parameter values as doubles so that the existing values will be incremented
by the passed values.
However, it cannot be used to achieve a percentage increase in font size. Below
is the code snippet to use the command.
|
SfRichTextBoxAdv.IncreaseFontSizeCommand.Execute(1.1, richTextBoxAdv); |
Iterating through the inlines (SpanAdv) within the selection and increasing
the font size:
In this scenario, we iterate through the inlines that lie within the selected
range and multiply the font size by 1.1 to increase it by 10% of the existing size.
We have also created a sample application that demonstrates the above two
methods. Based on your requirements, please use them.
Attachment: SfRichTextBoxAdv_FontSize_Increase_42af1014.zip
Thanks for the quick help, that's exactly what I needed! I will put this one change here for anyone who finds this later & wants to use the sample: the increaseFontSizebypercentage_Click method needs this block inserted just before the "// Check if the end index is within the length of the text" line. Otherwise the size changes affect the entire Inline that the selection start falls in, even if the selection starts in the middle of the Inline's text.
// Check if the start index is in the middle of a span
if (startIndex > 0 && startInline is SpanAdv startSpan)
{
// Create a new span containing the text prior to the split point
SpanAdv splitSpan = new() { Text = startSpan.Text[..startIndex] };
CopyFormat(startSpan.CharacterFormat, splitSpan.CharacterFormat);
// Modify the existing span to contain only text after the split point
startSpan.Text = startSpan.Text[startIndex..];
// Insert the new span immediately before the modified span in the paragraph
if (startSpan.Owner is ParagraphAdv paragraph)
{
paragraph.Inlines.Insert(paragraph.Inlines.IndexOf(startSpan), splitSpan);
}
// Refresh endInline to updated inline elements (startInline is still correct)
endInline = GetInline(endOffset, ref endIndex, richTextBoxAdv.Selection.End.Paragraph);
}
Rochelle, Thank you for the update! Please feel free to reach out to us if you need any further assistance.
- 3 Replies
- 2 Participants
- Marked answer
-
RB Rochelle Boggs
- Oct 28, 2024 05:53 PM UTC
- Oct 30, 2024 04:58 AM UTC