Text and Graphic Properties
The methods of the FixedContentEditor and Block classes create different content elements. Control the appearance of the newly created elements with the following properties:
GraphicProperties
These properties hold the current graphics control parameters. You can modify the following parameters through GraphicProperties:
-
IsFilled: A boolean property specifying whether content elements are filled. -
IsStroked: A boolean property specifying whether content elements are stroked. -
FillColor: The color used to fill the content elements. The property is of type ColorBase. -
StrokeColor: The color used to stroke the content elements. The property is of type ColorBase. -
StrokeThickness: The width of the stroke outline of content elements. The property is of typedouble. -
MiterLimit: Specifies the miter limit for graphic elements. The property is of typedouble?. -
StrokeDashOffset: The dash offset for graphic elements. The property is of typedouble. -
StrokeDashArray: The stroke dash array for graphic elements. The property is of typeIEnumerable<double>. -
StrokeLineJoin: The stroke line join for graphic elements. The property is of type LineJoin. -
StrokeLineCap: The stroke line cap for graphic elements. The property is of type LineCap.
Example 1: Using GraphicProperties with FixedContentEditor
editor.GraphicProperties.IsFilled = true;
editor.GraphicProperties.IsStroked = true;
editor.GraphicProperties.FillColor = new RgbColor(255, 0, 0);
editor.GraphicProperties.StrokeColor = RgbColors.Black;
editor.GraphicProperties.StrokeThickness = 2;
editor.GraphicProperties.StrokeDashArray = new double[] { 2, 2, 5 };
editor.GraphicProperties.StrokeLineJoin = Telerik.Windows.Documents.Fixed.Model.Graphics.LineJoin.Round;
TextProperties
These properties hold the parameters for text fragments. You can modify the following parameters through TextProperties:
-
UnderlinePattern: The underline pattern. The property is an enumeration of type UnderlinePattern. Two patterns are supported:None: There is no underline. This is the default value.Single: The underline is a single line.
-
UnderlineColor: The color of the underline. -
StrikethroughPattern: The strikethrough pattern. The property is an enumeration of type StrikethroughPattern. Two patterns are supported:None: There is no strikethrough. This is the default value.Single: The strikethrough is a single line.
-
StrikethroughColor: The color of the strikethrough. -
CharacterSpacing: The character spacing for text fragments. The property is of typedouble?. -
WordSpacing: The word spacing for text fragments. The property is of typedouble?. -
HorizontalScaling: The horizontal scaling for text fragments. The property is of typedouble?. -
FontSize: The font size for text fragments. The property is of typedouble. The measurement unit used for font size is Device Independent Pixels (DIPs). You can convert it to points or other units using the Unit class. -
RenderingMode: The rendering mode for text fragments. The property is of type RenderingMode. -
BaselineAlignment: Describes how the baseline for a text-based element is positioned on the vertical axis, relative to the established baseline for text. The property is an enumeration of type BaselineAlignment and exposes the following values:Baseline: A baseline that is aligned at the actual baseline of the containing box.Subscript: A baseline that is aligned at the subscript position of the containing box.Superscript: A baseline that is aligned at the superscript position of the containing box.
-
Font: The font for the inserted text, of type FontBase. -
HorizontalAlignment: The horizontal positioning of the inserted text in the text block. The property is of type HorizontalAlignment. -
VerticalAlignment: The vertical positioning of the inserted text in the text block. The property is of type VerticalAlignment.
Example 2: Using TextProperties with Block
Block block = new Block();
block.TextProperties.CharacterSpacing = 5;
block.TextProperties.Font = FontsRepository.TimesBold;
block.TextProperties.FontSize = Telerik.Windows.Documents.Media.Unit.PointToDip(12);
block.TextProperties.HighlightColor = new RgbColor(40, 60, 80);
block.TextProperties.RenderingMode = Telerik.Windows.Documents.Fixed.Model.Text.RenderingMode.FillAndStroke;
block.TextProperties.UnderlinePattern = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.UnderlinePattern.Single;
block.TextProperties.UnderlineColor = RgbColors.Black; ;
TextProperties also exposes the following methods for changing the current font:
-
TextProperties.TrySetFont(FontFamily fontFamily) -
TextProperties.TrySetFont(fontFamily, fontStyle, fontWeight)
In .NET Standard/.NET (Target OS: None) environments, fonts beyond the 14 standard ones require a FontsProvider implementation to be resolved correctly.
Preserving Current State
Both text and graphic properties contain methods that preserve and restore the current state.
-
properties.Save() -
properties.Restore()
The
Save()method returns anIDisposableobject that executesRestore()when the dispose method is called. You can use it in ausingstatement.