Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
FontRef.cs
1using SkiaSharp;
2using System.Collections.Generic;
3using System.Threading.Tasks;
4using System.Xml;
7
9{
13 public class FontRef : EmbeddedText
14 {
15 private StringAttribute font;
16
22 public FontRef(Layout2DDocument Document, ILayoutElement Parent)
23 : base(Document, Parent)
24 {
25 }
26
30 public override string LocalName => "FontRef";
31
36 {
37 get => this.font;
38 set => this.font = value;
39 }
40
45 public override Task FromXml(XmlElement Input)
46 {
47 this.font = new StringAttribute(Input, "font", this.Document);
48
49 return base.FromXml(Input);
50 }
51
56 public override void ExportAttributes(XmlWriter Output)
57 {
58 base.ExportAttributes(Output);
59
60 this.font?.Export(Output);
61 }
62
69 public override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
70 {
71 return new FontRef(Document, Parent);
72 }
73
78 public override void CopyContents(ILayoutElement Destination)
79 {
80 base.CopyContents(Destination);
81
82 if (Destination is FontRef Dest)
83 Dest.font = this.font?.CopyIfNotPreset(Destination.Document);
84 }
85
91 public override async Task MeasureSegments(List<Segment> Segments, DrawingState State)
92 {
93 EvaluationResult<string> FontId = await this.font.TryEvaluate(State.Session);
94
95 if (FontId.Ok &&
96 this.Document.TryGetElement(FontId.Result, out ILayoutElement E) &&
97 E is Font Font)
98 {
99 SKFont Bak = State.Font;
100 SKPaint Bak2 = State.Text;
101
102 State.Font = Font.FontDef;
103 State.Text = Font.Text;
104
105 await base.MeasureSegments(Segments, State);
106
107 State.Font = Bak;
108 State.Text = Bak2;
109 }
110 else
111 await base.MeasureSegments(Segments, State);
112 }
113
118 public override void ExportStateAttributes(XmlWriter Output)
119 {
120 base.ExportStateAttributes(Output);
121
122 this.font?.ExportState(Output);
123 }
124 }
125}
Contains a 2D layout document.
void Export(XmlWriter Output)
Exports the attribute.
Definition: Attribute.cs:187
void ExportState(XmlWriter Output)
Exports the state of the attribute.
Definition: Attribute.cs:199
static async Task< EvaluationResult< T > > TryEvaluate(Attribute< T > Attribute, Variables Session)
Tries to evaluate the attribute value.
Definition: Attribute.cs:256
StringAttribute CopyIfNotPreset(Layout2DDocument ForDocument)
Copies the attribute object if undefined, or defined by an expression. Returns a reference to itself,...
Abstract base class of embedded text elements in flowing text.
Definition: EmbeddedText.cs:14
Represents text using a specific font in flowing text.
Definition: FontRef.cs:14
override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
Creates a new instance of the layout element.
Definition: FontRef.cs:69
override void ExportStateAttributes(XmlWriter Output)
Exports the local attributes of the current element.
Definition: FontRef.cs:118
FontRef(Layout2DDocument Document, ILayoutElement Parent)
Represents text using a specific font in flowing text.
Definition: FontRef.cs:22
override void ExportAttributes(XmlWriter Output)
Exports attributes to XML.
Definition: FontRef.cs:56
override string LocalName
Local name of type of element.
Definition: FontRef.cs:30
override Task FromXml(XmlElement Input)
Populates the element (including children) with information from its XML definition.
Definition: FontRef.cs:45
override void CopyContents(ILayoutElement Destination)
Copies contents (attributes and children) to the destination element.
Definition: FontRef.cs:78
override async Task MeasureSegments(List< Segment > Segments, DrawingState State)
Measures text segments to a list of segments.
Definition: FontRef.cs:91
SKPaint Text
Current text paint settings
Variables Session
Current session.
Definition: DrawingState.cs:91
Abstract base class for fonts.
Definition: Font.cs:12
SKFont FontDef
Measured Font
Definition: Font.cs:245
SKPaint Text
Measured Text
Definition: Font.cs:250
Layout2DDocument Document
Layout document.
Base interface for all layout elements.
Layout2DDocument Document
Layout document.