Permalink
Browse files

D2d: Fix printing by using gdi for the print document. The Generator …

…of the PrintDocument/PrintPageEventArgs class should be used for all graphics operations
  • Loading branch information...
1 parent 0579ccc commit 5b5b2283a483369c1b2e4810782f22392418c5aa @cwensley cwensley committed Jan 10, 2014
@@ -79,6 +79,7 @@
<Compile Include="Drawing\TextureBrushHandler.cs" />
<Compile Include="Drawing\SolidBrushHandler.cs" />
<Compile Include="Forms\Controls\DrawableHandler.cs" />
+ <Compile Include="Forms\Printing\PrintDocumentHandler.cs" />
<Compile Include="Generator.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="..\Eto.Platform.Mac\Drawing\SplineHelper.cs">
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Eto.Platform.Direct2D.Forms.Printing
+{
+ public class PrintDocumentHandler : Eto.Platform.Windows.Forms.Printing.PrintDocumentHandler
+ {
+ protected override void Initialize()
+ {
+ base.Initialize();
+ // set to base generator to use gdi graphics
+ Generator = ((Eto.Platform.Direct2D.Generator)Generator).BaseGenerator;
+ }
+ }
+}
@@ -7,6 +7,7 @@
using Eto.IO;
using Eto.Platform.Direct2D.Drawing;
using Eto.Platform.Direct2D.Forms.Controls;
+using Eto.Platform.Direct2D.Forms.Printing;
namespace Eto.Platform.Direct2D
{
@@ -19,12 +20,21 @@ public override string ID
public Generator()
{
+ // generator to use for scenarios where direct 2d doesn't work (e.g. printing)
+ BaseGenerator = new Eto.Platform.Windows.Generator();
+
Eto.Platform.Windows.Generator.AddTo(this);
// This is added after the base class's assembly
AddTo(this);
}
+ public Eto.Generator BaseGenerator
+ {
+ get;
+ set;
+ }
+
public static new void AddTo(Eto.Generator g)
{
// Drawing
@@ -43,82 +53,10 @@ public static new void AddTo(Eto.Generator g)
g.Add<ILinearGradientBrush>(() => new LinearGradientBrushHandler());
// Forms.Cells
- //g.Add<ICheckBoxCell>(() => new CheckBoxCellHandler());
- //g.Add<IComboBoxCell>(() => new ComboBoxCellHandler());
- //g.Add<IImageTextCell>(() => new ImageTextCellHandler());
- //g.Add<IImageViewCell>(() => new ImageViewCellHandler());
- //g.Add<ITextBoxCell>(() => new TextBoxCellHandler());
-
- // Forms.Controls
- //g.Add<IButton>(() => new ButtonHandler());
- //g.Add<ICheckBox>(() => new CheckBoxHandler());
- //g.Add<IComboBox>(() => new ComboBoxHandler());
- //g.Add<IDateTimePicker>(() => new DateTimePickerHandler());
g.Add<IDrawable>(() => new DrawableHandler());
- //g.Add<IGridColumn>(() => new GridColumnHandler());
- //g.Add<IGridView>(() => new GridViewHandler());
- //g.Add<IGroupBox>(() => new GroupBoxHandler());
- //g.Add<IImageView>(() => new ImageViewHandler());
- //g.Add<ILabel>(() => new LabelHandler());
- //g.Add<IListBox>(() => new ListBoxHandler());
- //g.Add<INumericUpDown>(() => new NumericUpDownHandler());
- //g.Add<IPanel>(() => new PanelHandler());
- //g.Add<IPasswordBox>(() => new PasswordBoxHandler());
- //g.Add<IProgressBar>(() => new ProgressBarHandler());
- //g.Add<IRadioButton>(() => new RadioButtonHandler());
- //g.Add<IScrollable>(() => new ScrollableHandler());
- //g.Add<ISlider>(() => new SliderHandler());
- //g.Add<ISplitter>(() => new SplitterHandler());
- //g.Add<ITabControl>(() => new TabControlHandler());
- //g.Add<ITabPage>(() => new TabPageHandler());
- //g.Add<ITextArea>(() => new TextAreaHandler());
- //g.Add<ITextBox>(() => new TextBoxHandler());
- //g.Add<ITreeGridView>(() => new TreeGridViewHandler());
- //g.Add<ITreeView>(() => new TreeViewHandler());
- //g.Add<IWebView>(() => new WebViewHandler());
- //g.Add<IScreens>(() => new ScreensHandler());
-
- // Forms.Menu
- //g.Add<ICheckMenuItem>(() => new CheckMenuItemHandler());
- //g.Add<IContextMenu>(() => new ContextMenuHandler());
- //g.Add<IImageMenuItem>(() => new ImageMenuItemHandler());
- //g.Add<IMenuBar>(() => new MenuBarHandler());
- //g.Add<IRadioMenuItem>(() => new RadioMenuItemHandler());
- //g.Add<ISeparatorMenuItem>(() => new SeparatorMenuItemHandler());
// Forms.Printing
- //g.Add<IPrintDialog>(() => new PrintDialogHandler());
- //g.Add<IPrintDocument>(() => new PrintDocumentHandler());
- //g.Add<IPrintSettings>(() => new PrintSettingsHandler());
-
- // Forms.ToolBar
- //g.Add<ICheckToolBarButton>(() => new CheckToolBarButtonHandler());
- //g.Add<ISeparatorToolBarItem>(() => new SeparatorToolBarItemHandler());
- //g.Add<IToolBarButton>(() => new ToolBarButtonHandler());
- //g.Add<IToolBar>(() => new ToolBarHandler());
-
- // Forms
- //g.Add<IApplication>(() => new ApplicationHandler());
- //g.Add<IClipboard>(() => new ClipboardHandler());
- //g.Add<IColorDialog>(() => new ColorDialogHandler());
- //g.Add<ICursor>(() => new CursorHandler());
- //g.Add<IDialog>(() => new DialogHandler());
- //g.Add<IDockLayout>(() => new DockLayoutHandler());
- //g.Add<IFontDialog>(() => new FontDialogHandler());
- //g.Add<IForm>(() => new FormHandler());
- //g.Add<IMessageBox>(() => new MessageBoxHandler());
- //g.Add<IOpenFileDialog>(() => new OpenFileDialogHandler());
- //g.Add<IPixelLayout>(() => new PixelLayoutHandler());
- //g.Add<ISaveFileDialog>(() => new SaveFileDialogHandler());
- //g.Add<ISelectFolderDialog>(() => new SelectFolderDialogHandler());
- //g.Add<ITableLayout>(() => new TableLayoutHandler());
- //g.Add<IUITimer>(() => new UITimerHandler());
-
- // IO
- //g.Add<ISystemIcons>(() => new SystemIconsHandler());
-
- // General
- //g.Add<IEtoEnvironment>(() => new EtoEnvironmentHandler());
+ g.Add<IPrintDocument>(() => new PrintDocumentHandler());
}
}
}
@@ -89,15 +89,15 @@ PrintDocument GetPrintDocument()
{
var document = new PrintDocument();
document.PrintSettings = settings;
- var font = Fonts.Serif(16);
+ var font = Fonts.Serif(16, generator: document.Generator);
var printTime = DateTime.Now;
document.PrintPage += (sender, e) => {
Size pageSize = Size.Round(e.PageSize);
// draw a border around the printable area
var rect = new Rectangle(pageSize);
rect.Inflate(-1, -1);
- e.Graphics.DrawRectangle(Pens.Silver(), rect);
+ e.Graphics.DrawRectangle(Pens.Silver(e.Generator), rect);
// draw title
e.Graphics.DrawText(font, Colors.Black, new Point(50, 20), document.Name);
@@ -116,12 +116,12 @@ PrintDocument GetPrintDocument()
switch (e.CurrentPage)
{
case 0:
- e.Graphics.DrawRectangle(Pens.Blue(), new Rectangle(50, 50, 100, 100));
- e.Graphics.DrawRectangle(Pens.Green(), new Rectangle(new Point(pageSize) - new Size(150, 150), new Size(100, 100)));
+ e.Graphics.DrawRectangle(Pens.Blue(e.Generator), new Rectangle(50, 50, 100, 100));
+ e.Graphics.DrawRectangle(Pens.Green(e.Generator), new Rectangle(new Point(pageSize) - new Size(150, 150), new Size(100, 100)));
break;
case 1:
- e.Graphics.DrawRectangle(Pens.Blue(), new Rectangle(pageSize.Width - 150, 50, 100, 100));
- e.Graphics.DrawRectangle(Pens.Green(), new Rectangle(50, pageSize.Height - 150, 100, 100));
+ e.Graphics.DrawRectangle(Pens.Blue(e.Generator), new Rectangle(pageSize.Width - 150, 50, 100, 100));
+ e.Graphics.DrawRectangle(Pens.Green(e.Generator), new Rectangle(50, pageSize.Height - 150, 100, 100));
break;
}
};
@@ -17,6 +17,8 @@ public PrintPageEventArgs (Graphics graphics, SizeF pageSize, int currentPage)
this.PageSize = pageSize;
this.CurrentPage = currentPage;
}
+
+ public Generator Generator { get { return Graphics.Generator; } }
}
}

0 comments on commit 5b5b228

Please sign in to comment.