• R/O
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythonbathyscaphephpgamewindowsguic翻訳omegattwitterframeworktestbtronarduinovb.net計画中(planning stage)directxpreviewerゲームエンジンdom

デュアルディスプレイのセカンドモニターにPDFを表示。


コミットメタ情報

リビジョン49 (tree)
日時2018-11-28 13:28:26
作者bellyoshi

ログメッセージ

変更サマリ

差分

--- pdfsecondmonitor/ctlPdf.Designer.vb (revision 48)
+++ pdfsecondmonitor/ctlPdf.Designer.vb (revision 49)
@@ -66,9 +66,6 @@
6666 Me.btnPDFFirst.Text = "最初へ"
6767 Me.btnPDFFirst.UseVisualStyleBackColor = True
6868 '
69- 'BackgroundWorker1
70- '
71- '
7269 'btnNextHalf
7370 '
7471 Me.btnNextHalf.Location = New System.Drawing.Point(137, 75)
--- pdfsecondmonitor/ctlPdf.vb (revision 48)
+++ pdfsecondmonitor/ctlPdf.vb (revision 49)
@@ -36,9 +36,7 @@
3636 _viewer.OpenFile(f.FileName)
3737 End Sub
3838
39-
40-
41-
42-
43-
39+ Private Sub btnNextHalf_Click(sender As Object, e As EventArgs) Handles btnNextHalf.Click
40+ _viewer.NextHalfPage()
41+ End Sub
4442 End Class
--- pdfsecondmonitor/frmPdfViewer.vb (revision 48)
+++ pdfsecondmonitor/frmPdfViewer.vb (revision 49)
@@ -4,17 +4,20 @@
44 Dim pdfDoc As PdfDocument
55 Dim page As Integer = 0
66 Public Sub OpenFile(fileName As String)
7-
7+ isHalf = False
88 pdfDoc = PdfDocument.Load(fileName)
99 FirstPage()
1010 End Sub
1111
1212 Public Sub FirstPage()
13+
14+ isHalf = False
1315 page = 0
1416 DisplayPage()
1517 End Sub
1618
1719 Public Sub NextPage()
20+ isHalf = False
1821 If page < pdfDoc.PageCount Then
1922 page += 1
2023 DisplayPage()
@@ -22,6 +25,7 @@
2225 End Sub
2326
2427 Public Sub PrePage()
28+ isHalf = False
2529 If 0 < page Then
2630 page -= 1
2731 DisplayPage()
@@ -28,11 +32,73 @@
2832 End If
2933 End Sub
3034
35+ Private buttomInPage As Decimal
36+ Private _isHalf As Boolean
37+ Public Property isHalf As Boolean
38+ Set(value As Boolean)
39+ _isHalf = value
40+ If Not _isHalf Then
41+ buttomInPage = 0.0
42+ End If
43+ End Set
44+ Get
45+ Return _isHalf
46+ End Get
47+ End Property
48+ Public Sub NextHalfPage()
49+
50+ If Not isHalf Then
51+ page += 1
52+ End If
53+
54+ buttomInPage += 0.5
55+ If buttomInPage = 1.5 Then
56+ page += 1
57+ buttomInPage = 0.5
58+ End If
59+ isHalf = True
60+ DisplayHalfPage()
61+ End Sub
62+
63+ Private Sub DisplayHalfPage()
64+ If (page >= pdfDoc.PageCount) Then
65+ Return
66+ End If
67+ Dim pdfSize = pdfDoc.PageSizes(page)
68+ Dim sourceSize As New SizeF
69+ sourceSize.Height = pdfSize.Height / 2
70+ sourceSize.Width = pdfSize.Width
71+ Dim renderSize As Size? = GetRenderSize(sourceSize)
72+ If renderSize Is Nothing Then
73+ Return
74+ End If
75+ Dim r = renderSize.Value
76+ r.Height *= 2
77+ RenderHalf(r)
78+ End Sub
79+
80+ Private Sub RenderHalf(renderSize As Size)
81+ Dim height = renderSize.Height \ 2
82+ Dim width = renderSize.Width
83+ Dim canvas As New Bitmap(width, height)
84+ Using g As Graphics = Graphics.FromImage(canvas)
85+ Dim img = GetImage(renderSize)
86+ Dim y = renderSize.Height * (buttomInPage - 0.5)
87+ Dim srcRect As New Rectangle(0, y, width, height)
88+ Dim desRect As New Rectangle(0, 0, srcRect.Width, srcRect.Height)
89+ g.DrawImage(img, desRect, srcRect, GraphicsUnit.Pixel)
90+ End Using
91+ DispImage(canvas)
92+ End Sub
93+ Private Function GetImage(renderSize As Size)
94+ Return pdfDoc.Render(page, renderSize.Width, renderSize.Height, 96, 96, False)
95+ End Function
3196 Private Sub DisplayPage()
3297 If (page >= pdfDoc.PageCount) Then
3398 Return
3499 End If
35- Dim renderSize As Size? = GetRenderSize()
100+ Dim sourceSize = pdfDoc.PageSizes(page)
101+ Dim renderSize As Size? = GetRenderSize(sourceSize)
36102 If renderSize Is Nothing Then
37103 Return
38104 End If
@@ -39,9 +105,8 @@
39105 Render(renderSize)
40106 End Sub
41107
42- Private Function GetRenderSize() As Size?
108+ Private Function GetRenderSize(pdfSize As SizeF) As Size?
43109 Dim renderSize = New Size(PictureBox1.Size)
44- Dim pdfSize = pdfDoc.PageSizes(page)
45110 Dim pdfWdivH = pdfSize.Width / pdfSize.Height ' // pdfの縦横比
46111 Dim boxWdivH = PictureBox1.Width / PictureBox1.Height ' // コントロールの縦横比
47112 If (boxWdivH > 10) Then ' 落ちないよう
@@ -57,7 +122,11 @@
57122 End Function
58123
59124 Private Sub Render(renderSize As Size)
60- Dim img = pdfDoc.Render(page, renderSize.Width, renderSize.Height, 96, 96, False) ' // 解像度は意味ない?
125+ Dim img = GetImage(renderSize)
126+ DispImage(img)
127+ End Sub
128+
129+ Private Sub DispImage(img As Image)
61130 Dim oldImage = PictureBox1.Image
62131 PictureBox1.Image = img
63132 If oldImage IsNot Nothing Then