[EXAMPLES]

* NEW: Merge the new PDFViewer example made by Bernd Brinkmann.


git-svn-id: svn://localhost/gambas/trunk@5261 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2012-10-29 01:20:44 +00:00
parent 8edf201b34
commit fb2c780011
6 changed files with 435 additions and 117 deletions

View file

@ -1373,7 +1373,7 @@ msgstr ""
msgid "Expression"
msgstr ""
#: FDebugInfo.class:60 FProfile.class:599
#: FDebugInfo.class:60 FProfile.class:598
msgid "Function"
msgstr ""
@ -3557,43 +3557,43 @@ msgstr ""
msgid "Callers"
msgstr ""
#: FProfile.class:153
#: FProfile.class:152
msgid "Bad profile file format"
msgstr ""
#: FProfile.class:383
#: FProfile.class:382
msgid "&1 Mb"
msgstr ""
#: FProfile.class:383
#: FProfile.class:382
msgid "Total time &1 μs"
msgstr ""
#: FProfile.class:402
#: FProfile.class:401
msgid "Unable to load profile file: &1"
msgstr ""
#: FProfile.class:601
#: FProfile.class:600
msgid "Calls"
msgstr ""
#: FProfile.class:603
#: FProfile.class:602
msgid "Duration"
msgstr ""
#: FProfile.class:605
#: FProfile.class:604
msgid "Self"
msgstr ""
#: FProfile.class:607
#: FProfile.class:606
msgid "Average"
msgstr ""
#: FProfile.class:975
#: FProfile.class:974
msgid "Profile files"
msgstr ""
#: FProfile.class:982
#: FProfile.class:981
msgid "Unable to save profile."
msgstr ""

View file

@ -43,7 +43,6 @@ Private Sub GetClass(sFunc As String) As String
End
Fast Private Sub EnterFunction(sWhere As String, iTime As Long) As CProfile
Dim hProf As CProfile

View file

@ -1,9 +1,9 @@
# Gambas Project File 3.0
# Compiled with Gambas 3.0.0
# Compiled with Gambas 3.3.90
Title=PdfViewer
Startup=FMain
Icon=pdf.png
Version=3.0.0
Version=3.3.90
VersionFile=1
Component=gb.image
Component=gb.gui
@ -19,3 +19,4 @@ Maintainer=benoit
Vendor=Princeton
Address=benoit@localhost
License=General Public Licence
Packager=1

View file

@ -6,8 +6,8 @@
'
' PdfViewer gb.pdf component example
'
' (C) 2007 Daniel Campos Fernández <dcamposf@gmail.com>
'
' (C) 2007 Daniel Campos Fernández <dcamposf@gmail.com>
' 2012 Bernd Brinkmann (modifications on the search and zoom function) <brinkmann_bernd@gmx.de>
'
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
@ -31,9 +31,21 @@
'***************************************************************************
Public hPdf As New PdfDocument
Private timer_count As Integer
Public cIndex As Integer
Public CurrentPage As Integer
Public CurrentZoom As Float
Public CurrentZoom As Float = 1.0
Private bExit As Boolean
Private pdf_path As String
Private Embedded_In_Form As String
Private currentSearchResult As Short = 0 'Contains the information which of the search results on this page is marked
Private NumberOfSearchResults As Integer
Private currentSearchResultSynonyms As Short = 0
Private Product_Information_Dir As String
Private Synonyms As New String[20, 20]
Private ScrollXPositionBeforeZoom As Float
Private ScrollYPositionBeforeZoom As Float
Public Sub BtOpen_Click()
@ -56,16 +68,18 @@ Public Sub BtOpen_Click()
Else
BtNext.Enabled = False
End If
txtGotoPage.Enabled = True
btZoomIn.Enabled = True
btZoomOut.Enabled = True
btRotate.Enabled = True
pBox.Visible = True
TxtFind.Enabled = True
txtFind.Enabled = True
tvIndex.Clear()
If hPdf.HasIndex Then
tvIndex.Visible = True
AddIndex(0, "")
splIndex.Layout = [1, 3]
Else
tvIndex.Visible = False
End If
@ -106,49 +120,63 @@ Public Sub tvIndex_Click()
End
Public Sub RenderPage()
Public Sub RenderPage(Optional FoundText As String, Optional Casesensetivity As Boolean)
'---------------------------------------------------------------------------
'This function is called everytime something changed for example a new search result has to be displayed or the page
'has canged the parameters FoundText and Casesensetivity are only of interrest if the funktion is called from a search frunction
'--------------------------------------------------------------------------
Dim hPic As Picture
Dim Bc As Integer
Dim hPic As Picture
Dim Bc As Integer
ScrollXPositionBeforeZoom = ViewPort.ScrollX / ViewPort.ScrollWidth
ScrollYPositionBeforeZoom = ViewPort.ScrollY / ViewPort.ScrollHeight
hPdf.Zoom = CurrentZoom
LblInfo.Text = CurrentPage & " " & ("From") & " " & hPdf.Count
If CurrentZoom > 0.0 Then
hPdf.Zoom = CurrentZoom
Else
Message.Error("Can't set zoom to " & CurrentZoom, "OK")
Endif
ViewPort.Scroll(0, 0)
hPic = hPdf[CurrentPage].Image.Picture
lblInfo.Text = " of" & " " & hPdf.Count
If txtGotoPage.text <> CurrentPage Then txtGotoPage.text = CurrentPage 'if the parameter currentPage is different from the current page the current page gets changed
If currentSearchResult = 0 Then 'if a search result is highlighted the focus will not be changed to the top
ViewPort.Scroll(0, 0)
Endif
If TxtFind.Text <> "" Then
hPic = hPdf[CurrentPage].Image.Picture
hPdf[CurrentPage].Find(TxtFind.Text)
Paint.Begin(hPic)
Paint.Brush = Paint.Color(Color.RGB(0, 0, 255, 192))
For Bc = 0 To hPdf[CurrentPage].Result.Count - 1
Paint.Rectangle(hPdf[CurrentPage].Result[Bc].Left, hPdf[CurrentPage].Result[Bc].Top, hPdf[CurrentPage].Result[Bc].Width, hPdf[CurrentPage].Result[Bc].Height)
Next
Paint.Fill
Paint.End
'the search result gets highlighted here and the focus is set to the right position again if something has changed for example the zoomfactor
If currentSearchResult > 0 And FoundText <> "" Then ' resets the mark on the current search result
hPdf[CurrentPage].Find(FoundText, Casesensetivity)
Paint.Begin(hPic)
Paint.Brush = Paint.Color(Color.RGB(0, 0, 255, 192))
Paint.Rectangle(hPdf[CurrentPage].Result[currentSearchResult - 1].Left, hPdf[CurrentPage].Result[currentSearchResult - 1].Top, hPdf[CurrentPage].Result[currentSearchResult - 1].Width, hPdf[CurrentPage].Result[currentSearchResult - 1].Height)
ViewPort.ScrollY = ViewPort.ScrollHeight * (hPdf[CurrentPage].Result[currentSearchResult - 1].Top / Paint.Height)
Paint.Fill
Paint.End
PBox.Picture = hPic
Endif
End If
PBox.Picture = hPic
PBox.Resize(hPdf[CurrentPage].Width, hPdf[CurrentPage].Height)
Form_Resize()
PBox.Picture = hPic
PBox.Resize(hPdf[CurrentPage].Width, hPdf[CurrentPage].Height)
Form_Resize()
Catch
Balloon.Error(Error.Text, TxtFind)
Message.Info("An error occurred whilst trying to view the document.\n\nIf this persists please report this problem.")
End
Public Sub Form_Resize()
If CurrentPage = 0 Then Return
pBox.Left = (ViewPort.Width - hPdf[CurrentPage].Width) / 2
ViewPort.ScrollX = ScrollXPositionBeforeZoom * ViewPort.ScrollWidth
ViewPort.Scrolly = ScrollYPositionBeforeZoom * ViewPort.ScrollHeight
End
Public Sub HSplit1_Resize()
Public Sub splIndex_Resize()
Form_Resize()
@ -156,22 +184,31 @@ End
Public Sub BtNext_Click()
Inc CurrentPage
If CurrentPage = hPdf.Count Then BtNext.Enabled = False
BtPrev.Enabled = True
RenderPage()
Inc CurrentPage
currentSearchResult = 0
currentSearchResultSynonyms = 0
If CurrentPage = hPdf.Count Then
BtNext.Enabled = False
End If
BtPrev.Enabled = True
BtPrev.SetFocus
txtGotoPage.text = CurrentPage 'this automatically calls the function txtGotoPage_Change and changes the page to the new "currentPage"
End
Public Sub BtPrev_Click()
Dec CurrentPage
If CurrentPage = 1 Then BtPrev.Enabled = False
BtNext.Enabled = True
RenderPage()
Dec CurrentPage
currentSearchResult = 0
currentSearchResultSynonyms = 0
If CurrentPage = 1 Then
BtPrev.Enabled = False
End If
BtNext.Enabled = True
BtNext.SetFocus
txtGotoPage.text = CurrentPage 'this automatically calls the function txtGotoPage_Change and changes the page to the new "currentPage"
End
Public Sub btZoomIn_Click()
If CurrentZoom < 3 Then CurrentZoom += 0.1
@ -219,9 +256,245 @@ Public Sub btRotate_Click()
End
Public Sub TxtFind_Change()
Public Sub txtGotoPage_Change()
RenderPage()
'---------------------------------------------------------------------------
'This function changes the page to the page number written in the textbox "txtGotoPage"
'the text in this textbox can be changed by the user for example by klicking on the next button or other funktions such as
'a search funktion
'--------------------------------------------------------------------------
'
If Bexit Or Last.text = "" Then Return
'the last search results get removed by the next four lines
BtSearchNext.Enabled = False
BtSearchPrev.Enabled = False
currentSearchResult = 0
If Val(Last.text) > hPdf.Count Or Val(Last.text) = hPdf.Count Then 'hPdf.count contains the length of the pdf document
bExit = True
txtGotoPage.text = hPdf.Count
BtNext.Enabled = False 'because the last page is now displayed the next page button gets disabled
BtPrev.Enabled = True
bExit = False
Else
BtNext.Enabled = True
If Val(Last.text) = 1 Or Val(Last.text) < 1 Then
bExit = True
txtGotoPage.text = 1
bExit = False
BtPrev.Enabled = False
Else
BtPrev.Enabled = True
End If
End If
currentPage = Val(Last.text)
Bexit = False
RenderPage()
End
Public Sub txtGotoPage_KeyPress()
' If modUtil.AllowKeys(const.AllowKeys_NumbersOnly, Key.code) = False Then
' Stop Event
' Return
' End If
End
Public Sub txtFind_Activate()
'---------------------------------------------------------------------------
'This function is called if the user wants fo find the string inside the textbox "TxtFind" by hitting the enter key
'--------------------------------------------------------------------------
If Bexit Then Return
If txtFind.Text <> "" Then
If currentSearchResult > 0 Then
If currentSearchResult = NumberOfSearchResults Then
If currentpage = hPdf.Count Then
CurrentPage = 1
Else
CurrentPage = CurrentPage + 1
Endif
FindNext()
Else
currentSearchResult = currentSearchResult + 1
RenderPage(txtFind.Text)
Endif
Else
FindNext()
Endif
End If
End
Public Sub txtFind_Click()
txtFind_Activate
End
Private Sub FindNext()
'---------------------------------------------------------------------------
' This function finds the next string in the pdf matching the search string located after the current search result
'---------------------------------------------------------------------------
Dim hPic As Picture
Dim Bc As Integer
Dim currentSearchPage As Short = CurrentPage ' contains the information on which page the search funktion searched the last time
Dim LastPageToSearch As Short ' contains the information which page is the last page for the find function
If CurrentPage = 1 Then
LastPageToSearch = 1
Else
LastPageToSearch = CurrentPage
Endif
currentSearchResultSynonyms = 0
currentSearchResult = 0
BtSearchNext.Enabled = False
BtSearchPrev.Enabled = False
Repeat
hPic = hPdf[currentSearchPage].Image.Picture
hPdf[currentSearchPage].Find(txtFind.Text, False)
If hPdf[currentSearchPage].Result.Count > 0 Then
CurrentPage = currentsearchPage
currentSearchResult = 1
Else
If currentSearchPage = hPdf.Count Then
currentSearchPage = 1
Else
currentSearchPage = currentSearchPage + 1
Endif
Endif
Until currentSearchResult <> 0 Or currentSearchPage = LastPageToSearch
If hPdf[currentSearchPage].Result.Count > 0 Then
CurrentPage = currentSearchPage
txtGotoPage.text = CurrentPage
currentSearchResult = 1
NumberOfSearchResults = hPdf[currentSearchPage].Result.Count
BtSearchNext.Enabled = True
BtSearchPrev.Enabled = True
RenderPage(txtFind.Text)
Else
txtFind.Background = Color.Lighter(16711680) '16711680 = Red
RenderPage()
Endif
Catch
Message.Info("An error occurred whilst trying to view the document.\n\nIf this persists please report this problem.")
End
Private Sub FindPrevious()
'---------------------------------------------------------------------------
' This function finds the next string in the pdf matching the search string located before the current search result
'---------------------------------------------------------------------------
Dim hPic As Picture
Dim Bc As Integer
Dim currentSearchPage As Short = CurrentPage ' contains the information on which page the search funktion searched the last time
Dim LastPageToSearch As Short ' contains the information which page is the last page for the find function
If CurrentPage = hPdf.Count Then
LastPageToSearch = 0
Else
LastPageToSearch = CurrentPage
Endif
currentSearchResultSynonyms = 0
currentSearchResult = 0
BtSearchNext.Enabled = False
BtSearchPrev.Enabled = False
Repeat
hPic = hPdf[currentSearchPage].Image.Picture
hPdf[currentSearchPage].Find(txtFind.Text, False)
If hPdf[currentSearchPage].Result.Count > 0 Then
CurrentPage = currentsearchPage
currentSearchResult = 1
Else
If currentSearchPage = 1 Then
currentSearchPage = hPdf.Count
Else
currentSearchPage = currentSearchPage - 1
Endif
Endif
Until currentSearchResult <> 0 Or currentSearchPage = LastPageToSearch
If hPdf[currentSearchPage].Result.Count > 0 Then
CurrentPage = currentSearchPage
txtGotoPage.text = CurrentPage
currentSearchResult = hPdf[currentSearchPage].Result.Count
NumberOfSearchResults = hPdf[currentSearchPage].Result.Count
BtSearchNext.Enabled = True
BtSearchPrev.Enabled = True
RenderPage(txtFind.Text)
Endif
Catch
Message.Info("An error occurred whilst trying to view the document.\n\nIf this persists please report this problem.")
End
Public Sub BtSearchNext_Click()
'---------------------------------------------------------------------------
'This funktion is highlighting the next seach string located after the current search string
'---------------------------------------------------------------------------
If currentSearchResult = NumberOfSearchResults Then
If currentpage = hPdf.Count Then
CurrentPage = 1
Else
CurrentPage = CurrentPage + 1
Endif
FindNext()
Else
currentSearchResult = currentSearchResult + 1
RenderPage(txtFind.Text)
Endif
End
Public Sub BtSearchPrev_Click()
'---------------------------------------------------------------------------
'This funktion is highlighting the next seach string located before the current search string
'---------------------------------------------------------------------------
If currentSearchResult > 0 Then
If currentpage = 1 Then
currentpage = hPdf.Count
Else
CurrentPage = CurrentPage - 1
Endif
FindPrevious()
Else
currentSearchResult = currentSearchResult - 1
RenderPage(txtFind.Text)
Endif
End
Public Sub txtFind_Change()
'---------------------------------------------------------------------------
'When the user starts to type in a new search string this function removes all previous search results and in case
'the last search was not successful it turns the bachground color from red back to white
'---------------------------------------------------------------------------
If txtFind.Background = Color.Lighter(16711680) Then
txtFind.Background = Color.White
Endif
currentSearchResult = 0
currentSearchResultSynonyms = 0
BtSearchNext.Enabled = False
BtSearchPrev.Enabled = False
RenderPage()
End

View file

@ -5,91 +5,122 @@
Text = ("Simple PDF document viewer")
Arrangement = Arrange.Vertical
{ HBox1 HBox
MoveScaled(0,1,76,4)
MoveScaled(1,2,95,4)
{ BtOpen ToolButton
MoveScaled(0,0,4,4)
ToolTip = ("Open file...")
Text = ("")
Picture = Picture["icon:/small/open"]
}
{ Button1 ToolButton
MoveScaled(6,0,4,4)
MoveScaled(4,0,4,4)
ToolTip = ("About...")
Text = ("")
Picture = Picture["icon:/small/question"]
}
{ btRotate ToolButton
MoveScaled(10,0,4,4)
MoveScaled(8,0,4,4)
Enabled = False
ToolTip = ("Rotate")
Text = ("")
Picture = Picture["icon:/small/rotate-right"]
}
{ btZoomOut ToolButton
MoveScaled(14,0,4,4)
MoveScaled(12,0,4,4)
Enabled = False
ToolTip = ("Zoom out")
Text = ("")
Picture = Picture["icon:/small/zoom-out"]
}
{ btZoomIn ToolButton
MoveScaled(18,0,4,4)
MoveScaled(16,0,4,4)
Enabled = False
ToolTip = ("Zoom in")
Text = ("")
Picture = Picture["icon:/small/zoom-in"]
}
{ TxtFind TextBox
MoveScaled(24,0,12,4)
{ Separator3 Separator
MoveScaled(22,0,0,4)
}
{ txtFind ButtonBox
MoveScaled(24,0,15,4)
Enabled = False
ToolTip = ("Find text")
Expand = True
Text = ("")
Picture = Picture["icon:/small/find"]
Border = False
}
{ LblInfo Label
MoveScaled(44,0,15,4)
Expand = True
Text = ("")
Alignment = Align.Right
{ Panel1 Panel
MoveScaled(40,0,8,4)
Visible = False
Background = Color.TextBackground
{ BtSearchPrev Button
MoveScaled(0,0,4,4)
Enabled = False
ToolTip = ("Previous page")
Picture = Picture["icon:/small/left"]
Border = False
}
{ BtSearchNext Button
MoveScaled(4,0,4,4)
Enabled = False
Background = Color.TextBackground
ToolTip = ("Next Found")
Picture = Picture["icon:/small/right"]
Border = False
}
}
{ Separator1 Separator
MoveScaled(60,0,1,4)
MoveScaled(51,0,0,4)
}
{ BtPrev ToolButton
MoveScaled(61,0,4,4)
MoveScaled(54,0,4,4)
Enabled = False
ToolTip = ("Previous page")
Text = ("")
Picture = Picture["icon:/small/left"]
}
{ Page Label
MoveScaled(59,0,4,4)
AutoResize = True
Text = ("Page")
Alignment = Align.Right
}
{ Panel2 Panel
MoveScaled(64,0,1,4)
}
{ txtGotoPage TextBox
MoveScaled(66,0,9,4)
Enabled = False
ToolTip = ("Go to this page")
Alignment = Align.Center
Border = False
}
{ lblInfo Label
MoveScaled(75,0,7,4)
AutoResize = True
}
{ BtNext ToolButton
MoveScaled(68,0,4,4)
MoveScaled(84,0,4,4)
Enabled = False
ToolTip = ("Next page")
Text = ("")
Picture = Picture["icon:/small/right"]
}
}
{ HBox2 HBox
MoveScaled(1,10,75,38)
{ Separator2 Separator
MoveScaled(36,8,27,0)
}
{ splIndex HSplit
MoveScaled(9,11,81,60)
Expand = True
{ HSplit1 HSplit
MoveScaled(4,3,66,35)
{ tvIndex TreeView
MoveScaled(0,0,19,25)
Visible = False
Border = False
}
{ ViewPort ScrollView
MoveScaled(36,5,30,32)
Background = Color.TextBackground
Expand = True
{ tvIndex TreeView
MoveScaled(0,0,19,25)
Border = False
{ PBox PictureBox
MoveScaled(3,3,24,21)
Visible = False
}
{ ViewPort ScrollView
MoveScaled(21,1,30,32)
Background = Color.TextBackground
Expand = True
Border = False
{ PBox PictureBox
MoveScaled(3,2,24,21)
Visible = False
}
}
}
}
}

View file

@ -1,18 +1,32 @@
# Gambas Form File 3.0
{ Form Form
MoveScaled(0,0,65,18)
Text = ("")
MoveScaled(0,0,48,22)
Resizable = False
{ btOK Button
MoveScaled(21,13,23,4)
Text = ("OK")
Default = True
Cancel = True
}
Arrangement = Arrange.Vertical
Spacing = True
Margin = True
{ TextLabel1 TextLabel
MoveScaled(0,0,65,11)
Text = ("Simple PDF document viewer.<p>Gambas example by Daniel Campos Fern\xC3\xA1ndez ")
MoveScaled(2,2,45,13)
Expand = True
Text = ("<h2>Simple PDF document viewer</h2><p>Gambas example by Daniel Campos Fernández and Bernd Brinkmann")
Alignment = Align.Center
}
{ Panel1 HBox
MoveScaled(13,16,32,4)
{ Panel2 Panel
MoveScaled(4,0,2,4)
Expand = True
}
{ btOK Button
MoveScaled(10,0,15,4)
Text = ("OK")
Default = True
Cancel = True
}
{ Panel3 Panel
MoveScaled(26,0,2,4)
Expand = True
}
}
}