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
|
||||
}
|
||||
|
@ -153,15 +153,20 @@ namespace zaaReloaded2.Formatter
|
||||
|
||||
string name = IncludeMaterial ? LabItem.QualifiedName : LabItem.Name;
|
||||
|
||||
// Insert the formatted text into the document.
|
||||
formatter.Write(
|
||||
string output =
|
||||
String.Format(
|
||||
"{0} {1}{2}{3}",
|
||||
name,
|
||||
value,
|
||||
unit,
|
||||
reference
|
||||
));
|
||||
);
|
||||
if (!LabItem.IsNormal)
|
||||
{
|
||||
output = String.Format("<b>{0}</b>", output);
|
||||
}
|
||||
|
||||
formatter.Write(output);
|
||||
HasBeenUsed = true;
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ namespace zaaReloaded2.Formatter
|
||||
|
||||
static string FormatHeader(string text)
|
||||
{
|
||||
return String.Format("{0}Laborwerte vom {1}:{2}",
|
||||
return String.Format("{0}<b>Laborwerte vom {1}:</b>{2}",
|
||||
Environment.NewLine,
|
||||
text,
|
||||
Environment.NewLine
|
||||
|
@ -123,7 +123,8 @@ namespace zaaReloaded2.LabModel
|
||||
public bool HasUpperLimit { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Is true if <see cref="Value"/> is normal.
|
||||
/// Is true if <see cref="Value"/> is normal. Returns true
|
||||
/// if no limits and no normal value are known.
|
||||
/// </summary>
|
||||
public bool IsNormal
|
||||
{
|
||||
@ -147,7 +148,7 @@ namespace zaaReloaded2.LabModel
|
||||
}
|
||||
else
|
||||
{
|
||||
return (Value == Normal);
|
||||
return String.IsNullOrEmpty(Normal) || (Value == Normal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -347,7 +347,7 @@ namespace zaaReloaded2.ViewModels
|
||||
picker.ElementChosenMessage.Sent += (sender, args) =>
|
||||
{
|
||||
ElementViewModel newVM = args.Content.ViewModel as ElementViewModel;
|
||||
if (IsTopLevelElement())
|
||||
if (LastSelectedElement == null || IsTopLevelElement())
|
||||
{
|
||||
AddElementViewModel(newVM);
|
||||
}
|
||||
|
Reference in New Issue
Block a user