Implement bold font; make tests pass again.
- NEU: Überschriften und pathologische Werte werden fett gedruckt. - FIX: Kleinere Bugfixes.
This commit is contained in:
@ -20,6 +20,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Office.Interop.Word;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace zaaReloaded2.Formatter
|
||||
{
|
||||
@ -59,6 +60,20 @@ namespace zaaReloaded2.Formatter
|
||||
/// </summary>
|
||||
public string ParagraphStyle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns text without markup from the buffer.
|
||||
/// </summary>
|
||||
public string Text
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!HasBufferedText)
|
||||
throw new InvalidOperationException("This DocumentWriter does not have any text.");
|
||||
|
||||
return _markupRegex.Replace(_buffer.ToString(), String.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@ -126,7 +141,7 @@ namespace zaaReloaded2.Formatter
|
||||
{
|
||||
s.set_Style(ParagraphStyle);
|
||||
}
|
||||
s.Range.Text = _buffer.ToString();
|
||||
MarkupToDocument(_buffer.ToString());
|
||||
}
|
||||
if (Parent != null)
|
||||
{
|
||||
@ -166,9 +181,40 @@ namespace zaaReloaded2.Formatter
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
||||
/// <summary>
|
||||
/// 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);
|
||||
foreach (string substring in substrings)
|
||||
{
|
||||
switch (substring)
|
||||
{
|
||||
case "<b>":
|
||||
Document.ActiveWindow.Selection.Font.Bold = 1;
|
||||
break;
|
||||
case "</b>":
|
||||
Document.ActiveWindow.Selection.Font.Bold = 0;
|
||||
break;
|
||||
default:
|
||||
Document.ActiveWindow.Selection.TypeText(substring);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
|
||||
StringBuilder _buffer;
|
||||
// Put pattern in parentheses so they will not be discarded by Regex.Split
|
||||
static readonly Regex _markupRegex = new Regex(@"(</?b>)");
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
Reference in New Issue
Block a user