-
-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rendering engine should be able to support spans of characters with different formats #10
Comments
@tocsoft I think I can implement this once we have a design. Here's an early bash... I would add a collection of a type to public struct TextRun
{
public uint Start; // (inclusive, measured in codepoints)
public uint End; // (exclusive, measured in codepoints)
public Font? Font; // Can be used to override the default font.
TextAttributes Attributes;
} public class TextAttributes : List<TextAttribute>
{
} public enum TextAttribute
{
Underline,
Strikethough,
// Others?...
// Subscript,
// Superscript,
} Questions.
|
hmm... with This would be significantly simpler design if we hadn't moved We can still do that but it if we still had the separate As a side note/follow on item we might want to add a simple mark up language option/extension too, but that should probably be handled on the Drawing side having it responsible for converting the mark up into text and Runs. |
I actually looked at that first and am still considering it.
One way to do it while avoiding generics and keeping it strongly typed is to take advantage of the covariance capabilities of If we change all our methods currently accepting public class TextRun
{
public uint Start; // (inclusive, measured in codepoints)
public uint End; // (exclusive, measured in codepoints)
public Font Font; // Can be used to override the default font.
public TextAttributes Attributes;
}
public class TextAttributes : List<TextAttribute>
{
}
public enum TextAttribute
{
Underline,
Strikethough,
Subscript,
Superscript,
}
public interface ITextOptions
{
// All our preexisting text options
IEnumerable<TextRun> TextRuns { get; set; }
}
public class TextOptions : ITextOptions
{
// All our preexisting text options
public IEnumerable<TextRun> TextRuns { get; set; }
}
public class TextDrawingRun : TextRun
{
public IPen Pen { get; set; }
public IBrush Brush { get; set; }
}
public class TextDrawingOptions : ITextOptions
{
public IEnumerable<TextDrawingRun> TextRuns
{
get { return (IEnumerable<TextDrawingRun>)((ITextOptions)this).TextRuns; }
set { ((ITextOptions)this).TextRuns = value; }
}
IEnumerable<TextRun> ITextOptions.TextRuns { get; set; }
} |
Yeah that looks generally looks good to me... we could do it without the interface too just by inheriting Something more like this; New APIs inside Fontspublic class TextRun
{
public uint Start; // (inclusive, measured in codepoints)
public uint End; // (exclusive, measured in codepoints)
public Font Font; // Can be used to override the default font.
public TextAttributes Attributes;
}
public class TextAttributes : List<TextAttribute>
{
}
public enum TextAttribute
{
Underline,
Strikethough,
Subscript,
Superscript,
} Altered Apis in Fonts- public sealed class TextOptions
+ public class TextShaperOptions
{
// All our pre-existing text options
+ public IEnumerable<TextRun> TextRuns { get; set; }
// for the default case where there is no matching
+ public TextAttributes Attributes;
} New APi inside Drawingpublic class TextDrawingRun : TextRun
{
public IPen Pen { get; set; }
public IBrush Brush { get; set; }
}
public class TextOptions : TextShapingOptions
{
// shadow the TextShapingOptions Runs
// The glyph render would not actually be depended on this property directly this is only for authoring
// glyph renderer will `as` cast each Run as returned during rendering (IGlypheRenderer) to determine
// the altered rendering data to use
public new IEnumerable<TextDrawingRun> TextRuns
{
get { return (IEnumerable<TextDrawingRun>)base.TextRuns; }
set { base.TextRuns = value; }
}
} |
Ah yes! That's the way to do it! One thing I can't decide is whether to stick with the I'd have to design something to make identifying Edit - |
Provide a mechanisum for marking up spans of the supplied text with different formats allowing for simple rich text support
i.e. The quick brown fox jumps over the lazy dog
would use the below proposed font style
The text was updated successfully, but these errors were encountered: