Skip to content

Commit 06f19f2

Browse files
committed
fixed problem with the applying PDF page orientation for the GhostscriptViewer and the GhostscriptRasterizer
1 parent 9a37156 commit 06f19f2

File tree

5 files changed

+98
-0
lines changed

5 files changed

+98
-0
lines changed

Ghostscript.NET/Ghostscript.NET.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
<Compile Include="GhostscriptDisplayDeviceHandler.cs" />
9090
<Compile Include="GhostscriptLibrary.cs" />
9191
<Compile Include="GhostscriptLicense.cs" />
92+
<Compile Include="GhostscriptPageOrientation.cs" />
9293
<Compile Include="GhostscriptPdfInfo.cs" />
9394
<Compile Include="GhostscriptPipedOutput.cs" />
9495
<Compile Include="GhostscriptRectangle.cs" />
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// GhostscriptPageOrientation.cs
3+
// This file is part of Ghostscript.NET library
4+
//
5+
// Author: Josip Habjan (habjan@gmail.com, http://www.linkedin.com/in/habjan)
6+
// Copyright (c) 2013-2014 by Josip Habjan. All rights reserved.
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining
9+
// a copy of this software and associated documentation files (the
10+
// "Software"), to deal in the Software without restriction, including
11+
// without limitation the rights to use, copy, modify, merge, publish,
12+
// distribute, sublicense, and/or sell copies of the Software, and to
13+
// permit persons to whom the Software is furnished to do so, subject to
14+
// the following conditions:
15+
//
16+
// The above copyright notice and this permission notice shall be
17+
// included in all copies or substantial portions of the Software.
18+
//
19+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23+
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24+
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25+
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26+
27+
using System;
28+
29+
namespace Ghostscript.NET
30+
{
31+
public enum GhostscriptPageOrientation : int
32+
{
33+
Portrait = 0,
34+
Seascape = 1,
35+
UpsideDown = 2,
36+
Landscape = 3
37+
}
38+
}

Ghostscript.NET/Viewer/FormatHandlers/GhostscriptViewerPdfFormatHandler.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,33 @@ public override void StdOutput(string message)
163163
}
164164
case PDF_ROTATE_TAG:
165165
{
166+
int rotate = int.Parse(rest);
167+
168+
while (rotate < 0)
169+
{
170+
rotate += 360;
171+
}
172+
173+
while (rotate >= 360)
174+
{
175+
rotate -= 360;
176+
}
177+
178+
switch (rotate)
179+
{
180+
case 90:
181+
this.PageOrientation = GhostscriptPageOrientation.Landscape;
182+
break;
183+
case 180:
184+
this.PageOrientation = GhostscriptPageOrientation.UpsideDown;
185+
break;
186+
case 270:
187+
this.PageOrientation = GhostscriptPageOrientation.Seascape;
188+
break;
189+
default:
190+
this.PageOrientation = GhostscriptPageOrientation.Portrait;
191+
break;
192+
}
166193

167194
break;
168195
}

Ghostscript.NET/Viewer/GhostscriptViewer.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,8 @@ public void ShowPage(int pageNumber, bool refresh)
503503
this.Interpreter.Run(string.Format("/GraphicsAlphaBits {0}\n", _graphicsAlphaBits));
504504
this.Interpreter.Run(string.Format("/TextAlphaBits {0}\n", _textAlphaBits));
505505

506+
this.Interpreter.Run(string.Format("/Orientation {0}\n", (int)this.CurrentPageOrientation));
507+
506508
this.Interpreter.Run(">> setpagedevice\n");
507509

508510
this.Interpreter.Run(
@@ -984,6 +986,25 @@ public bool EPSClip
984986

985987
#endregion
986988

989+
#region CurrentPageOrientation
990+
991+
public GhostscriptPageOrientation CurrentPageOrientation
992+
{
993+
get
994+
{
995+
if (this.IsEverythingInitialized)
996+
{
997+
return _formatHandler.PageOrientation;
998+
}
999+
else
1000+
{
1001+
return GhostscriptPageOrientation.Landscape;
1002+
}
1003+
}
1004+
}
1005+
1006+
#endregion
1007+
9871008
#endregion
9881009

9891010
#region Internal properties

Ghostscript.NET/Viewer/GhostscriptViewerFormatHandler.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ internal abstract class GhostscriptViewerFormatHandler : IDisposable
4242
private GhostscriptRectangle _mediaBox = GhostscriptRectangle.Empty;
4343
private GhostscriptRectangle _boundingBox = GhostscriptRectangle.Empty;
4444
private GhostscriptRectangle _cropBox = GhostscriptRectangle.Empty;
45+
private GhostscriptPageOrientation _pageOrientation = GhostscriptPageOrientation.Portrait;
4546
private bool _showPagePostScriptCommandInvoked = false;
4647

4748
#endregion
@@ -212,6 +213,16 @@ public bool IsCropBoxSet
212213

213214
#endregion
214215

216+
#region PageOrientation
217+
218+
public GhostscriptPageOrientation PageOrientation
219+
{
220+
get { return _pageOrientation; }
221+
set { _pageOrientation = value; }
222+
}
223+
224+
#endregion
225+
215226
#region ShowPageInvoked
216227

217228
internal bool ShowPagePostScriptCommandInvoked

0 commit comments

Comments
 (0)