namespace Avalonia.Media.TextFormatting
{
///
/// Generic implementation of TextParagraphProperties
///
public sealed class GenericTextParagraphProperties : TextParagraphProperties
{
private FlowDirection _flowDirection;
private TextAlignment _textAlignment;
private TextWrapping _textWrap;
private double _lineHeight;
///
/// Constructing TextParagraphProperties
///
/// default paragraph's default run properties
/// logical horizontal alignment
/// text wrap option
/// Paragraph line height
/// letter spacing
public GenericTextParagraphProperties(TextRunProperties defaultTextRunProperties,
TextAlignment textAlignment = TextAlignment.Left,
TextWrapping textWrap = TextWrapping.NoWrap,
double lineHeight = 0,
double letterSpacing = 0)
{
DefaultTextRunProperties = defaultTextRunProperties;
_textAlignment = textAlignment;
_textWrap = textWrap;
_lineHeight = lineHeight;
LetterSpacing = letterSpacing;
}
///
/// Constructing TextParagraphProperties
///
/// text flow direction
/// logical horizontal alignment
/// true if the paragraph is the first line in the paragraph
/// true if the line is always collapsible
/// default paragraph's default run properties
/// text wrap option
/// Paragraph line height
/// line indentation
/// letter spacing
public GenericTextParagraphProperties(
FlowDirection flowDirection,
TextAlignment textAlignment,
bool firstLineInParagraph,
bool alwaysCollapsible,
TextRunProperties defaultTextRunProperties,
TextWrapping textWrap,
double lineHeight,
double indent,
double letterSpacing)
{
_flowDirection = flowDirection;
_textAlignment = textAlignment;
FirstLineInParagraph = firstLineInParagraph;
AlwaysCollapsible = alwaysCollapsible;
DefaultTextRunProperties = defaultTextRunProperties;
_textWrap = textWrap;
_lineHeight = lineHeight;
LetterSpacing = letterSpacing;
Indent = indent;
}
///
/// Constructing TextParagraphProperties from another one
///
/// source line props
public GenericTextParagraphProperties(TextParagraphProperties textParagraphProperties)
: this(textParagraphProperties.FlowDirection,
textParagraphProperties.TextAlignment,
textParagraphProperties.FirstLineInParagraph,
textParagraphProperties.AlwaysCollapsible,
textParagraphProperties.DefaultTextRunProperties,
textParagraphProperties.TextWrapping,
textParagraphProperties.LineHeight,
textParagraphProperties.Indent,
textParagraphProperties.LetterSpacing)
{
}
///
/// This property specifies whether the primary text advance
/// direction shall be left-to-right, right-to-left, or top-to-bottom.
///
public override FlowDirection FlowDirection
{
get { return _flowDirection; }
}
///
/// This property describes how inline content of a block is aligned.
///
public override TextAlignment TextAlignment
{
get { return _textAlignment; }
}
///
/// Paragraph's line height
///
public override double LineHeight
{
get { return _lineHeight; }
}
///
/// Indicates the first line of the paragraph.
///
public override bool FirstLineInParagraph { get; }
///
/// If true, the formatted line may always be collapsed. If false (the default),
/// only lines that overflow the paragraph width are collapsed.
///
public override bool AlwaysCollapsible { get; }
///
/// Paragraph's default run properties
///
public override TextRunProperties DefaultTextRunProperties { get; }
///
/// This property controls whether or not text wraps when it reaches the flow edge
/// of its containing block box
///
public override TextWrapping TextWrapping
{
get { return _textWrap; }
}
///
/// Line indentation
///
public override double Indent { get; }
///
/// The letter spacing
///
public override double LetterSpacing { get; }
///
/// Set text flow direction
///
internal void SetFlowDirection(FlowDirection flowDirection)
{
_flowDirection = flowDirection;
}
///
/// Set text alignment
///
internal void SetTextAlignment(TextAlignment textAlignment)
{
_textAlignment = textAlignment;
}
///
/// Set line height
///
internal void SetLineHeight(double lineHeight)
{
_lineHeight = lineHeight;
}
///
/// Set text wrap
///
internal void SetTextWrapping(TextWrapping textWrap)
{
_textWrap = textWrap;
}
}
}