Implement text styles.
- NEU: Überschriften und pathologische Werte werden jetzt besonders ausgezeichnet (fett).
This commit is contained in:
@ -31,8 +31,19 @@ namespace zaaReloaded2.Formatter
|
||||
/// depending on whether there is text in the buffer or not.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// Linking several DocumentWriters permits a cascading work flow
|
||||
/// with several buffers.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Markup support: The DocumentWriter supports basic markup to control
|
||||
/// the text styles in the Word document.
|
||||
/// </para>
|
||||
/// <list type="unordered">
|
||||
/// <item><b> and </b> - bold/unbold</item>
|
||||
/// <item><style:NAME> - set the paragraph or character style</item>
|
||||
/// <item></style> - remove *character* style</item>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
class DocumentWriter
|
||||
{
|
||||
@ -54,12 +65,6 @@ namespace zaaReloaded2.Formatter
|
||||
/// </summary>
|
||||
public bool HasBufferedText { get { return _buffer.Length > 0; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the desired paragraph style when flushing into
|
||||
/// a Document.
|
||||
/// </summary>
|
||||
public string ParagraphStyle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns text without markup from the buffer.
|
||||
/// </summary>
|
||||
@ -137,10 +142,6 @@ namespace zaaReloaded2.Formatter
|
||||
Selection s = Document.ActiveWindow.Selection;
|
||||
s.ClearCharacterDirectFormatting();
|
||||
s.ClearParagraphDirectFormatting();
|
||||
if (!string.IsNullOrEmpty(ParagraphStyle))
|
||||
{
|
||||
s.set_Style(ParagraphStyle);
|
||||
}
|
||||
MarkupToDocument(_buffer.ToString());
|
||||
}
|
||||
if (Parent != null)
|
||||
@ -187,22 +188,33 @@ namespace zaaReloaded2.Formatter
|
||||
/// Parses a string containing markup (e.g., "<b>", "</b>")
|
||||
/// and writes formatted text to the current Document.
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
void MarkupToDocument(string text)
|
||||
{
|
||||
string[] substrings = _markupRegex.Split(text);
|
||||
Selection sel = Document.ActiveWindow.Selection;
|
||||
foreach (string substring in substrings)
|
||||
{
|
||||
switch (substring)
|
||||
{
|
||||
case "<b>":
|
||||
Document.ActiveWindow.Selection.Font.Bold = 1;
|
||||
sel.Font.Bold = 1;
|
||||
break;
|
||||
case "</b>":
|
||||
Document.ActiveWindow.Selection.Font.Bold = 0;
|
||||
sel.Font.Bold = 0;
|
||||
break;
|
||||
case "</style>":
|
||||
sel.ClearCharacterStyle();
|
||||
break;
|
||||
default:
|
||||
Document.ActiveWindow.Selection.TypeText(substring);
|
||||
Match styleMatch = _styleRegex.Match(substring);
|
||||
if (styleMatch.Success)
|
||||
{
|
||||
sel.set_Style(styleMatch.Groups["style"].Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
sel.TypeText(substring);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -214,7 +226,10 @@ namespace zaaReloaded2.Formatter
|
||||
|
||||
StringBuilder _buffer;
|
||||
// Put pattern in parentheses so they will not be discarded by Regex.Split
|
||||
static readonly Regex _markupRegex = new Regex(@"(</?b>)");
|
||||
// The splitting pattern must not contain subgroups!
|
||||
static readonly Regex _markupRegex = new Regex(@"(<[^>]+>)");
|
||||
static readonly Regex _styleRegex = new Regex(@"<style:(?<style>[^>]+)>");
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
Reference in New Issue
Block a user