Skip to content

Commit

Permalink
IPrintProcessor.GetCustomPageContent allows to positionize custom e…
Browse files Browse the repository at this point in the history
…lements on any page.
  • Loading branch information
michaelmairegger committed Sep 11, 2017
1 parent 453604a commit 1494584
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 4 deletions.
32 changes: 30 additions & 2 deletions Mairegger.Printing/Content/DirectPrintContent.cs
Expand Up @@ -16,9 +16,37 @@ namespace Mairegger.Printing.Content
{
using System.Windows;

public abstract class DirectPrintContent : IPrintContent
/// <inheritdoc />
/// <summary>
/// A print content that can be positionized freely on the page.
/// </summary>
/// <remarks>
/// By returning an instance of this class from a
/// <see cref="M:Mairegger.Printing.PrintProcessor.IPrintProcessor.ItemCollection" />
/// or <see cref="M:Mairegger.Printing.PrintProcessor.IPrintProcessor.GetCustomPageContent(System.Int32)" /> following
/// behaviors apply:
/// <list type="bullets">
/// <listheader>
/// <term>Method</term>
/// <description>Behavior</description>
/// </listheader>
/// <item>
/// <term>
/// <see cref="M:Mairegger.Printing.PrintProcessor.IPrintProcessor.ItemCollection" />
/// </term>
/// <description>The object is printed on the current page.</description>
/// </item>
/// <item>
/// <term>
/// <see cref="M:Mairegger.Printing.PrintProcessor.IPrintProcessor.GetCustomPageContent(System.Int32)" />
/// </term>
/// <description>The item can be printed on any page that is desired.</description>
/// </item>
/// </list>
/// </remarks>
public class DirectPrintContent : IDirectPrintContent
{
public abstract UIElement Content { get; }
public virtual UIElement Content { get; set; }

public Point Position { get; set; }
}
Expand Down
26 changes: 26 additions & 0 deletions Mairegger.Printing/Content/IDirectPrintContent.cs
@@ -0,0 +1,26 @@
// Copyright 2017 Michael Mairegger
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Mairegger.Printing.Content
{
using System.Windows;

public interface IDirectPrintContent : IPrintContent
{
/// <summary>
/// Gets the position where the <see cref="IPrintContent.Content" /> should be printed.
/// </summary>
Point Position { get; }
}
}
1 change: 0 additions & 1 deletion Mairegger.Printing/Content/IPrintContent.cs
Expand Up @@ -15,7 +15,6 @@
namespace Mairegger.Printing.Content
{
using System.Windows;
using Mairegger.Printing.PrintProcessor;

/// <summary>
/// Interface that provides the line-data for the <see cref="PrintProcessor" />
Expand Down
19 changes: 18 additions & 1 deletion Mairegger.Printing/Internal/InternalPrintProcessor.cs
Expand Up @@ -79,6 +79,14 @@ public FixedDocument CreateFixedDocument(PrintProcessorCollection collection)
{
AddPageNumbers(currentPage);
}

for (int i = currentPage,
j = 1;
i < FixedDocument.Pages.Count;
i++, j++)
{
AddCustomPositionizedContent(FixedDocument.Pages[i], _printProcessor.GetCustomPageContent(j));
}
}

if (!collection.IndividualPageNumbers)
Expand All @@ -103,6 +111,15 @@ private static void PositionizeUiElement(PageContent pageContent, UIElement fram
pageContent.Child.Children.Add(frameworkElement);
}

private static void AddCustomPositionizedContent(PageContent page, IEnumerable<IDirectPrintContent> customContent)
{
foreach (var content in customContent)
{
PositionizeUiElement(page, content.Content, content.Position);
}
}


private void AddBackground(PageContent pageContent, bool isLastpage)
{
if (!_printProcessor.PrintDefinition.IsToPrint(PrintAppendixes.Background, CurrentPageNumber, isLastpage))
Expand Down Expand Up @@ -176,7 +193,7 @@ private void AddLineItem(IPrintContent item, bool isLast)
{
AddLineItem((IPageBreakAware)item, isLast);
}
else if (item is DirectPrintContent directPrintContent)
else if (item is IDirectPrintContent directPrintContent)
{
var position = new Point(directPrintContent.Position.X + _pageHelper.PrintingDimension.Margin.Left, directPrintContent.Position.Y + _pageHelper.PrintingDimension.Margin.Top);
PositionizeUiElement(_pageHelper.PageContent, item.Content, position);
Expand Down
1 change: 1 addition & 0 deletions Mairegger.Printing/Mairegger.Printing.csproj
Expand Up @@ -74,6 +74,7 @@
<Compile Include="Content\DirectContentLineItem.cs" />
<Compile Include="Content\DirectPrintContent.cs" />
<Compile Include="Content\HorizontalLine.cs" />
<Compile Include="Content\IDirectPrintContent.cs" />
<Compile Include="Content\IPageBreakAware.cs" />
<Compile Include="Content\PrintContent.cs" />
<Compile Include="Content\StringLineItem.cs" />
Expand Down
8 changes: 8 additions & 0 deletions Mairegger.Printing/PrintProcessor/IPrintProcessor.cs
Expand Up @@ -128,5 +128,13 @@ public interface IPrintProcessor : IPrintProcessorPrinter
/// </summary>
/// <returns> A collection containing the print contents </returns>
IEnumerable<IPrintContent> ItemCollection();


/// <summary>
/// Returns a list of <see cref="IDirectPrintContent"/> to allow custom positionizing element on the page.
/// </summary>
/// <param name="pageNumber">The current page number. The numbering starts with 1.</param>
/// <returns></returns>
IEnumerable<IDirectPrintContent> GetCustomPageContent(int pageNumber);
}
}
5 changes: 5 additions & 0 deletions Mairegger.Printing/PrintProcessor/PrintProcessor.cs
Expand Up @@ -95,6 +95,11 @@ public static bool PrintDocument(IPrintDialog printDialog, PrintProcessorCollect
return true;
}

public virtual IEnumerable<IDirectPrintContent> GetCustomPageContent(int pageNumber)
{
yield break;
}

/// <summary>
/// Sets the global configuration of the <see cref="IPrintDialog"/>. This action is applied before each print.
/// </summary>
Expand Down

0 comments on commit 1494584

Please sign in to comment.